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.

classification
Title: [doc] Class __dict__ is only a mapping proxy
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Jim Fasarakis-Hilliard, docs@python, iritkatriel, martin.panter, slateny
Priority: normal Keywords: easy

Created on 2017-01-12 12:04 by martin.panter, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
class-dict.patch martin.panter, 2017-01-12 12:04 review
Messages (7)
msg285313 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2017-01-12 12:04
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.
msg290655 - (view) Author: Jim Fasarakis-Hilliard (Jim Fasarakis-Hilliard) * Date: 2017-03-27 21:19
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?
msg290668 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2017-03-27 23:55
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).
msg290882 - (view) Author: Jim Fasarakis-Hilliard (Jim Fasarakis-Hilliard) * Date: 2017-03-30 21:05
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-mappingproxy

Changing it to just state it's a mapping definitely looks like the safest option.
msg407708 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-12-05 12:47
The patch would still apply to Doc/library/functions.rst.


https://docs.python.org/3.10/reference/datamodel.html#the-standard-type-hierarchy  seems to have been changed quite a lot, but still has:

1. "Special read-only attribute: __dict__ is the module’s namespace as a dictionary object."


2. "__dict__
The dictionary containing the class’s namespace."
msg414140 - (view) Author: Stanley (slateny) * Date: 2022-02-27 04:33
From what I can see, the original patch changed

... and the *dict* dictionary is the namespace containing definitions for class body and is copied to a standard dictionary to become the __dict__ attribute

into this

... and the *dict* dictionary is copied to the namespace containing definitions for the class body, which is referenced by the __dict__ attribute

so that the documentation avoids saying that the attribute is a dictionary, instead saying it just references a dictionary. However, current documentation says that

... it may be copied or wrapped before becoming the __dict__ attribute

which implies some sort of change already. In this case, is the patch for the functions page still applicable?
msg414771 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-03-08 19:38
Thank you Stanley, I agree that this is no longer needed.
History
Date User Action Args
2022-04-11 14:58:41adminsetgithub: 73437
2022-03-08 19:38:48iritkatrielsetstatus: open -> closed
resolution: out of date
messages: + msg414771

stage: patch review -> resolved
2022-02-27 04:33:01slatenysetnosy: + slateny
messages: + msg414140
2021-12-05 12:47:05iritkatrielsetnosy: + iritkatriel
versions: + Python 3.9, Python 3.10, Python 3.11, - Python 2.7, Python 3.5, Python 3.6, Python 3.7
messages: + msg407708

keywords: + easy, - patch
title: Class __dict__ is only a mapping proxy -> [doc] Class __dict__ is only a mapping proxy
2017-03-30 21:05:29Jim Fasarakis-Hilliardsetmessages: + msg290882
2017-03-27 23:55:01martin.pantersetmessages: + msg290668
2017-03-27 21:19:00Jim Fasarakis-Hilliardsetnosy: + Jim Fasarakis-Hilliard
messages: + msg290655
2017-01-12 12:04:20martin.pantercreate