[issue42088] types.SimpleNamespace.__repr__ documentation inconsistency

Eric Snow report at bugs.python.org
Wed Jun 9 16:42:43 EDT 2021


Eric Snow <ericsnowcurrently at gmail.com> added the comment:

> According to the documentation for types.SimpleNamespace, `repr(SimpleNamespace())`
> should return `"SimpleNamespace()"`, but in actuality returns `"namespace()"`.

Note that I purposefully wrote "roughly" in the docs ("The type is roughly equivalent to the following code:").  That code was meant to illustrate the functionality rather than be proscriptive of the implementation.  That said, it certainly would be good for the documentation to match. :)

> but also the (perhaps less interesting issue) of `eval(repr(SimpleNamespace))` resulting in a NameError.

This is true of many of the types exposed by the types module (e.g. types.CodeType).

> I propose that `_PyNamespaceObject`'s __repr__ method be changed to return `"SimpleNamespace(<args>)"`.

My preference would be as outlined in my previous comment: make it a builtin.  However, I'm not in a position to make that happen at the moment.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42088>
_______________________________________


More information about the Python-bugs-list mailing list