| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -1946,10 +1946,12 @@ Once the appropriate metaclass has been identified, then the class namespace | |
| is prepared. If the metaclass has a ``__prepare__`` attribute, it is called | ||
| as ``namespace = metaclass.__prepare__(name, bases, **kwds)`` (where the | ||
| additional keyword arguments, if any, come from the class definition). The | ||
| ``__prepare__`` method should be implemented as a :func:`classmethod`. | ||
| ``__prepare__`` method should be implemented as a :func:`classmethod`. The | ||
| namespace returned by ``__prepare__`` is passed in to ``__new__``, but when | ||
| the final class object is created the namespace is copied into a new ``dict``. | ||
|
|
||
| If the metaclass has no ``__prepare__`` attribute, then the class namespace | ||
| is initialised as an empty ordered mapping. | ||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityPer PEP 520, the default class namespace must be an ordered mapping and the original text here was purposefully phrased. While we've talked about requiring "dict" to be ordered (in the language reference), that hasn't happened. So changing the language spec text here to "dict" is inappropriate without a PEP. Note that elsewhere in the language reference the "ordered mapping" phrasing still exists.
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityUm, dict is required to be ordered. Since 3.7. See the 3.7. what's new doc "the insertion-order preservation nature of dict objects has been declared to be an official part of the Python language spec." If after that has sunk in you still think this PR is wrong, please submit a new PR to fix it! (Sorry for landing prematurely.)
Sorry, something went wrong.
ericsnowcurrently reacted with thumbs up emoji
All reactions
Copy link
Copy Markdown
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityPer my comment on the bpo I think @ericsnowcurrently is right but for the wrong reasons. I have opened a PR correcting the wording. #18682
Sorry, something went wrong.
All reactions
|
||
| is initialised as an empty :func:`dict`. | ||
|
|
||
| .. seealso:: | ||
|
|
||
| Expand Down | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| The language reference now specifies restrictions on class namespaces. Adapted from a patch by Ethan Furman. |
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.