New submission from Eric Snow:
(related to PEP 422 and issue #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-creati...
---------- assignee: docs@python components: Documentation messages: 184188 nosy: docs@python, eric.snow, ncoghlan priority: normal severity: normal stage: needs patch status: open title: language reference should specify restrictions on class namespace type: enhancement versions: Python 3.4
_______________________________________ Python tracker report@bugs.python.org http://bugs.python.org/issue17422 _______________________________________
Changes by Daniel Urban urban.dani+py@gmail.com:
---------- nosy: +daniel.urban
_______________________________________ Python tracker report@bugs.python.org http://bugs.python.org/issue17422 _______________________________________
Changes by Ethan Furman ethan@stoneleaf.us:
---------- nosy: +ethan.furman
_______________________________________ Python tracker report@bugs.python.org http://bugs.python.org/issue17422 _______________________________________
Changes by Ethan Furman ethan@stoneleaf.us:
---------- keywords: +patch stage: needs patch -> patch review versions: +Python 3.5 Added file: http://bugs.python.org/file37712/issue17422.stoneleaf.01.patch
_______________________________________ Python tracker report@bugs.python.org http://bugs.python.org/issue17422 _______________________________________
Changes by Ethan Furman ethan@stoneleaf.us:
---------- nosy: -ethan.furman
_______________________________________ Python tracker report@bugs.python.org http://bugs.python.org/issue17422 _______________________________________
Change by Caleb Donovick donovick@cs.stanford.edu:
---------- nosy: +donovick
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue17422 _______________________________________
Change by Ananthakrishnan ananthakrishnan15.2001@gmail.com:
---------- pull_requests: +17939 pull_request: https://github.com/python/cpython/pull/18559
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue17422 _______________________________________
Ananthakrishnan ananthakrishnan15.2001@gmail.com added the comment:
I just addded a PR for this issue.
---------- nosy: +Ananthakrishnan
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue17422 _______________________________________
Guido van Rossum guido@python.org added the comment:
New changeset fbe2e0bb8a7ee75d0f9d57682436dac7d69e202e by ananthan-123 in branch 'master': bpo-17422: Language reference should specify restrictions on class namespace (#18559) https://github.com/python/cpython/commit/fbe2e0bb8a7ee75d0f9d57682436dac7d69...
---------- nosy: +gvanrossum
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue17422 _______________________________________
Change by Guido van Rossum guido@python.org:
---------- resolution: -> fixed stage: patch review -> resolved status: open -> closed
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue17422 _______________________________________
Change by miss-islington mariatta.wijaya+miss-islington@gmail.com:
---------- pull_requests: +17975 pull_request: https://github.com/python/cpython/pull/18610
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue17422 _______________________________________
Change by miss-islington mariatta.wijaya+miss-islington@gmail.com:
---------- pull_requests: +17976 pull_request: https://github.com/python/cpython/pull/18611
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue17422 _______________________________________
miss-islington mariatta.wijaya+miss-islington@gmail.com added the comment:
New changeset 91ba44623e5cb8f4a7b0d3fc1fab8ff8d8a849c2 by Miss Islington (bot) in branch '3.8': bpo-17422: Language reference should specify restrictions on class namespace (GH-18559) https://github.com/python/cpython/commit/91ba44623e5cb8f4a7b0d3fc1fab8ff8d8a...
---------- nosy: +miss-islington
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue17422 _______________________________________
miss-islington mariatta.wijaya+miss-islington@gmail.com added the comment:
New changeset 36a120d343c1cb69b8d02913569c153e8bb969c8 by Miss Islington (bot) in branch '3.7': bpo-17422: Language reference should specify restrictions on class namespace (GH-18559) https://github.com/python/cpython/commit/36a120d343c1cb69b8d02913569c153e8bb...
----------
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue17422 _______________________________________
Eric Snow ericsnowcurrently@gmail.com added the comment:
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] https://github.com/python/cpython/pull/18559#pullrequestreview-366098695
---------- resolution: fixed -> stage: resolved -> needs patch status: closed -> open versions: +Python 3.7, Python 3.8, Python 3.9 -Python 3.4, Python 3.5
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue17422 _______________________________________
Guido van Rossum guido@python.org added the comment:
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.
----------
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue17422 _______________________________________
Caleb Donovick donovick@cs.stanford.edu added the comment:
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__.
----------
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue17422 _______________________________________
Change by Caleb Donovick donovick@cs.stanford.edu:
---------- pull_requests: +18041 stage: needs patch -> patch review pull_request: https://github.com/python/cpython/pull/18682
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue17422 _______________________________________
Change by Guido van Rossum guido@python.org:
---------- nosy: -gvanrossum
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue17422 _______________________________________
miss-islington mariatta.wijaya+miss-islington@gmail.com added the comment:
New changeset e59334ebc9308b0f3ad048ef293c6b49e6456d1a by Caleb Donovick in branch 'master': bpo-17422: slightly more precise language (GH-18682) https://github.com/python/cpython/commit/e59334ebc9308b0f3ad048ef293c6b49e64...
----------
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue17422 _______________________________________
Change by miss-islington mariatta.wijaya+miss-islington@gmail.com:
---------- pull_requests: +18170 pull_request: https://github.com/python/cpython/pull/18812
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue17422 _______________________________________
Change by miss-islington mariatta.wijaya+miss-islington@gmail.com:
---------- pull_requests: +18171 pull_request: https://github.com/python/cpython/pull/18813
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue17422 _______________________________________
miss-islington mariatta.wijaya+miss-islington@gmail.com added the comment:
New changeset f1b79645cf18b2c212cd26d547cd1762fd534d4b by Miss Islington (bot) in branch '3.7': bpo-17422: slightly more precise language (GH-18682) https://github.com/python/cpython/commit/f1b79645cf18b2c212cd26d547cd1762fd5...
----------
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue17422 _______________________________________
miss-islington mariatta.wijaya+miss-islington@gmail.com added the comment:
New changeset 6df0c47669031c6a8e9b1a07ec2c5813e4c10ee0 by Miss Islington (bot) in branch '3.8': bpo-17422: slightly more precise language (GH-18682) https://github.com/python/cpython/commit/6df0c47669031c6a8e9b1a07ec2c5813e4c...
----------
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue17422 _______________________________________
Eric Snow ericsnowcurrently@gmail.com added the comment:
Thanks for fixing that, Caleb!
FWIW, I've opened a separate issue (#39879) for adding a note in the language reference about dict ordering. Sorry for the confusion.
---------- resolution: -> fixed stage: patch review -> resolved status: open -> closed
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue17422 _______________________________________
Ned Deily nad@python.org added the comment:
New changeset 22448149a05b5bc3e3a2ffdc0682bcd01995ce2a by Ned Deily (Miss Islington (bot)) in branch '3.7': bpo-17422: slightly more precise language (GH-18682) https://github.com/python/cpython/commit/22448149a05b5bc3e3a2ffdc0682bcd0199...
---------- nosy: +ned.deily
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue17422 _______________________________________