Message303843
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'. |
|
Date |
User |
Action |
Args |
2017-10-06 18:52:51 | terry.reedy | set | recipients:
+ terry.reedy, rhettinger, vstinner, r.david.murray, eric.snow, serhiy.storchaka |
2017-10-06 18:52:51 | terry.reedy | set | messageid: <1507315971.95.0.213398074469.issue31655@psf.upfronthosting.co.za> |
2017-10-06 18:52:51 | terry.reedy | link | issue31655 messages |
2017-10-06 18:52:51 | terry.reedy | create | |
|