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 jugmac00
Recipients jugmac00
Date 2020-11-13.13:42:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1605274926.75.0.147847269171.issue42344@roundup.psfhosted.org>
In-reply-to
Content
When tinkering around with `SimpleNamespace` I tried to figure out the reasons for using it over just the `class NS: pass` alternative.

One reason is the comparison, which is not a plain `id` comparison, but an attribute comparison.

When looking at the documentation of the imaginary python implementation, where only dicts are compared, the reader (me) could think you can compare it to classes.
https://docs.python.org/3/library/types.html?highlight=simplenamespace#types.SimpleNamespace

```
>>> from types import SimpleNamespace
>>> simple_ns = SimpleNamespace(a=1, b="two")

>>> class NS: pass
>>> class_ns = NS()
>>> class_ns.a = 1
>>> class_ns.b = "two"

>>> simple_ns == class_ns
>>> False
```

Actually, the C implementation compares the types, too.
https://github.com/python/cpython/blob/bc777047833256bc6b10b2c7b46cce9e9e6f956c/Objects/namespaceobject.c#L163-L171

While the documentation says the Python impl is "roughly equivalent", 
I's still suggest to update the documentation.

If there is some agreement, I'd create a pull request.
History
Date User Action Args
2020-11-13 13:42:06jugmac00setrecipients: + jugmac00
2020-11-13 13:42:06jugmac00setmessageid: <1605274926.75.0.147847269171.issue42344@roundup.psfhosted.org>
2020-11-13 13:42:06jugmac00linkissue42344 messages
2020-11-13 13:42:06jugmac00create