Terry J. Reedy <[email protected]> added the comment:
After reading the doc entry for SimpleNamespace, I see running
'SimpleNamespace(**{0:0})' as a bug because doing so results in an object than
contradicts the doc.
1. "A simple object subclass that provides attribute access to its namespace,
as well as a meaningful repr. Unlike ... you can ... delete attributes."
But, after 'sn = SimpleNamespace(**{0:0})', sn.0 is a SyntaxError and
getattr(sn, 0) raises 'TypeError: getattr(): attribute name must be string'.
As already noted, the 'attribute' does not appear in repr(sn). 'del sn.0' and
'delattr(sn, 0)' also fail. If this is a feature, it is extremely buggy.
2. "The type is roughly equivalent to the following code:"
class SimpleNamespace:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def __repr__(self):
keys = sorted(self.__dict__)
items = ("{}={!r}".format(k, self.__dict__[k]) for k in keys)
return "{}({})".format(type(self).__name__, ", ".join(items))
def __eq__(self, other):
return self.__dict__ == other.__dict__
With this definition, SimpleNamespace(**{0:0}) raises TypeError. To me,
running versus raising is outside the bounds of 'roughly equivalent'.
----------
nosy: +terry.reedy
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue31655>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com