-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
language reference should specify restrictions on class namespace #61624
Comments
(related to PEP-422 and issue bpo-17044) The execution namespace from a class definition is passed as the third argument to the metaclass (see builtin___build_class__() in Python/bltinmodule.c). When applicable, which is almost always, the subsequent call to type.__new__() copies that namespace into a new dict which is in turn exposed via the class's __dict__. This matters in the case where a metaclass with __prepare__() gets used (or the PEP-422 equivalent). The language reference[1] should note that the object returned by __prepare__() is copied into a new dict when the class is finally created via the metaclass. [1] http://docs.python.org/3.4/reference/datamodel.html#customizing-class-creation |
I just addded a PR for this issue. |
Thanks for working on this. Sorry I didn't get a chance to see your PR sooner. There was one small thing that needs to be changed back, as I implied in my comment on the PR [1]. Please undo the change in the text from "ordered mapping" to "dict". The original "is initialised as an empty ordered mapping" text line should be restored. "dict" is currently still not correct (the language spec does not dictate that dict be ordered). However, PEP-520 specifies that it must be ordered. Thanks! [1] #18559 (review) |
As I mentioned in my response on the PR, dict *is* required to be ordered since 3.7. So I think it is okay as is. |
While It is perfectly fine behavior for CPython to use a dict, as dict is an ordered mapping. I think Eric is right that the data model should not specify that a dict is necessarily used in the absence of __prepare__. |
Thanks for fixing that, Caleb! FWIW, I've opened a separate issue (bpo-39879) for adding a note in the language reference about dict ordering. Sorry for the confusion. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: