This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients eric.snow, r.david.murray, rhettinger, serhiy.storchaka, terry.reedy, vstinner
Date 2017-10-06.18:52:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1507315971.95.0.213398074469.issue31655@psf.upfronthosting.co.za>
In-reply-to
Content
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'.
History
Date User Action Args
2017-10-06 18:52:51terry.reedysetrecipients: + terry.reedy, rhettinger, vstinner, r.david.murray, eric.snow, serhiy.storchaka
2017-10-06 18:52:51terry.reedysetmessageid: <1507315971.95.0.213398074469.issue31655@psf.upfronthosting.co.za>
2017-10-06 18:52:51terry.reedylinkissue31655 messages
2017-10-06 18:52:51terry.reedycreate