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: language reference should specify restrictions on class namespace
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Ananthakrishnan, daniel.urban, docs@python, donovick, eric.snow, miss-islington, ncoghlan, ned.deily
Priority: normal Keywords: patch

Created on 2013-03-14 20:33 by eric.snow, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue17422.stoneleaf.01.patch ethan.furman, 2015-01-15 05:20 review
Pull Requests
URL Status Linked Edit
PR 18559 merged Ananthakrishnan, 2020-02-19 11:11
PR 18610 merged miss-islington, 2020-02-22 17:59
PR 18611 merged miss-islington, 2020-02-22 18:00
PR 18682 merged donovick, 2020-02-28 01:41
PR 18812 merged miss-islington, 2020-03-06 18:21
PR 18813 merged miss-islington, 2020-03-06 18:21
Messages (13)
msg184188 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2013-03-14 20:33
(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-creation
msg362272 - (view) Author: Ananthakrishnan (Ananthakrishnan) * Date: 2020-02-19 13:59
I just addded a PR for this issue.
msg362470 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2020-02-22 17:56
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/fbe2e0bb8a7ee75d0f9d57682436dac7d69e202e
msg362479 - (view) Author: miss-islington (miss-islington) Date: 2020-02-22 21:16
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/91ba44623e5cb8f4a7b0d3fc1fab8ff8d8a849c2
msg362480 - (view) Author: miss-islington (miss-islington) Date: 2020-02-22 21:16
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/36a120d343c1cb69b8d02913569c153e8bb969c8
msg362853 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2020-02-28 00:54
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
msg362854 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2020-02-28 00:58
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.
msg362856 - (view) Author: Caleb Donovick (donovick) * Date: 2020-02-28 01:08
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__.
msg363530 - (view) Author: miss-islington (miss-islington) Date: 2020-03-06 18:20
New changeset e59334ebc9308b0f3ad048ef293c6b49e6456d1a by Caleb Donovick in branch 'master':
bpo-17422: slightly more precise language (GH-18682)
https://github.com/python/cpython/commit/e59334ebc9308b0f3ad048ef293c6b49e6456d1a
msg363531 - (view) Author: miss-islington (miss-islington) Date: 2020-03-06 18:25
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/f1b79645cf18b2c212cd26d547cd1762fd534d4b
msg363532 - (view) Author: miss-islington (miss-islington) Date: 2020-03-06 18:26
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/6df0c47669031c6a8e9b1a07ec2c5813e4c10ee0
msg363534 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2020-03-06 18:38
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.
msg363807 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2020-03-10 07:48
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/22448149a05b5bc3e3a2ffdc0682bcd01995ce2a
History
Date User Action Args
2022-04-11 14:57:42adminsetgithub: 61624
2020-03-10 07:48:52ned.deilysetnosy: + ned.deily
messages: + msg363807
2020-03-06 18:38:42eric.snowsetstatus: open -> closed
resolution: fixed
messages: + msg363534

stage: patch review -> resolved
2020-03-06 18:26:56miss-islingtonsetmessages: + msg363532
2020-03-06 18:25:54miss-islingtonsetmessages: + msg363531
2020-03-06 18:21:21miss-islingtonsetpull_requests: + pull_request18171
2020-03-06 18:21:15miss-islingtonsetpull_requests: + pull_request18170
2020-03-06 18:20:52miss-islingtonsetmessages: + msg363530
2020-02-28 01:57:22gvanrossumsetnosy: - gvanrossum
2020-02-28 01:41:56donovicksetstage: needs patch -> patch review
pull_requests: + pull_request18041
2020-02-28 01:08:11donovicksetmessages: + msg362856
2020-02-28 00:58:09gvanrossumsetmessages: + msg362854
2020-02-28 00:54:37eric.snowsetstatus: closed -> open
versions: + Python 3.7, Python 3.8, Python 3.9, - Python 3.4, Python 3.5
messages: + msg362853

resolution: fixed -> (no value)
stage: resolved -> needs patch
2020-02-22 21:16:46miss-islingtonsetmessages: + msg362480
2020-02-22 21:16:28miss-islingtonsetnosy: + miss-islington
messages: + msg362479
2020-02-22 18:00:06miss-islingtonsetpull_requests: + pull_request17976
2020-02-22 17:59:58miss-islingtonsetpull_requests: + pull_request17975
2020-02-22 17:58:21gvanrossumsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-02-22 17:56:05gvanrossumsetnosy: + gvanrossum
messages: + msg362470
2020-02-19 13:59:02Ananthakrishnansetnosy: + Ananthakrishnan
messages: + msg362272
2020-02-19 11:11:02Ananthakrishnansetpull_requests: + pull_request17939
2020-02-07 20:06:14donovicksetnosy: + donovick
2015-07-21 07:36:01ethan.furmansetnosy: - ethan.furman
2015-01-15 05:20:52ethan.furmansetfiles: + issue17422.stoneleaf.01.patch
keywords: + patch
stage: needs patch -> patch review
versions: + Python 3.5
2014-05-19 01:34:10ethan.furmansetnosy: + ethan.furman
2013-03-16 12:56:01ncoghlanlinkissue17421 dependencies
2013-03-14 21:56:42daniel.urbansetnosy: + daniel.urban
2013-03-14 20:33:35eric.snowcreate