Title: types.SimpleNamespace.__repr__ documentation inconsistency
Type: Stage: patch review
Components: Library (Lib) Versions: Python 3.10
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: ZackerySpytz, avrahami.ben
Priority: normal Keywords: patch

Created on 2020-10-19 20:34 by avrahami.ben, last changed 2020-11-24 21:00 by ZackerySpytz.

Pull Requests
URL Status Linked Edit
PR 23502 open ZackerySpytz, 2020-11-24 21:00
Messages (1)
msg379010 - (view) Author: Ben Avrahami (avrahami.ben) * Date: 2020-10-19 20:34
According to the documentation for types.SimpleNamespace, `repr(SimpleNamespace())` should return `"SimpleNamespace()"`, but in actuality returns `"namespace()"`. This is because SimpleNamespace is an alias for the C implemented type `_PyNamespaceObject`. Interestingly, `_PyNamespaceObject` names itself `"types.SimpleNamespace"`. This has the obvious issue of the documentation being wrong, but also the (perhaps less interesting issue) of `eval(repr(SimpleNamespace))` resulting in a NameError.

I propose that `_PyNamespaceObject`'s __repr__ method be changed to return `"SimpleNamespace(<args>)"`. This would require only the change of a constant in one line (currently this is line 75 on namespaceobject.c).

A smaller fix would be to change the documentation to correctly reflect this behavior.
Date User Action Args
2020-11-24 21:00:40ZackerySpytzsetkeywords: + patch
nosy: + ZackerySpytz

pull_requests: + pull_request22391
stage: patch review
2020-10-19 20:34:54avrahami.bencreate