New submission from Jürgen Gmach <juergen.gm...@googlemail.com>:

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.

----------
messages: 380882
nosy: jugmac00
priority: normal
severity: normal
status: open
title: SimpleNamespace: update documentation regarding comparison

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue42344>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to