[issue29251] Class __dict__ is only a mapping proxy
New submission from Martin Panter: The __dict__ attribute of class objects is documented as being a (standard) dictionary, but implemented with a proxy object. I propose to clarify the documentation in “Custom classes” under <https://docs.python.org/3.5/reference/datamodel.html#the-standard-type-hierarchy>, and in <https://docs.python.org/3.5/library/functions.html#type>. I believe my changes are also applicable to Python 2, as long as I point out the proxy is specific to “new-style” classes. ---------- assignee: docs@python components: Documentation files: class-dict.patch keywords: patch messages: 285313 nosy: docs@python, martin.panter priority: normal severity: normal stage: patch review status: open title: Class __dict__ is only a mapping proxy type: behavior versions: Python 2.7, Python 3.5, Python 3.6, Python 3.7 Added file: http://bugs.python.org/file46268/class-dict.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29251> _______________________________________
Jim Fasarakis-Hilliard added the comment: Isn't the fact that it's read-only a CPython implementation detail? That is, shouldn't that just read: "gives a :term:`mapping` object representing the class's namespace" so as to not enforce anything on any other implementations? ---------- nosy: +Jim Fasarakis-Hilliard _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29251> _______________________________________
Martin Panter added the comment: I don’t know if it is an implementation detail or not. Maybe it is the documentation itself which defines that. Anyway, I think your wording would have been fine for my original problem. I wonder if we should clarify that only reading the mapping is supported, even if we don’t define any particular behaviour for modifying it (like updating the namespace, raising an exception, ignoring the change, etc). ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29251> _______________________________________
Jim Fasarakis-Hilliard added the comment: I believe the docs defined that, usually using a bold "CPython implementation detail" sentence. It seems like it's something that would be considered an implementation detail, though, according to Raymond's answer here: http://stackoverflow.com/questions/32720492/why-is-a-class-dict-a-mappingpro... Changing it to just state it's a mapping definitely looks like the safest option. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29251> _______________________________________
participants (2)
-
Jim Fasarakis-Hilliard
-
Martin Panter