[Python-checkins] bpo-17422: Language reference should specify restrictions on class namespace (GH-18559)

Miss Islington (bot) webhook-mailer at python.org
Sat Feb 22 16:16:47 EST 2020


https://github.com/python/cpython/commit/36a120d343c1cb69b8d02913569c153e8bb969c8
commit: 36a120d343c1cb69b8d02913569c153e8bb969c8
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2020-02-22T13:16:43-08:00
summary:

bpo-17422: Language reference should specify restrictions on class namespace (GH-18559)


The language reference now specifies restrictions on class namespaces.  Adapted from a patch by Ethan Furman.
(cherry picked from commit fbe2e0bb8a7ee75d0f9d57682436dac7d69e202e)

Co-authored-by: ananthan-123 <ananthakrishnan15.2001 at gmail.com>

files:
A Misc/NEWS.d/next/Documentation/2020-02-19-11-13-47.bpo-17422.g7_9zz.rst
M Doc/reference/datamodel.rst

diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst
index d25357db43468..b682465d3ddc8 100644
--- a/Doc/reference/datamodel.rst
+++ b/Doc/reference/datamodel.rst
@@ -1932,10 +1932,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.
+is initialised as an empty :func:`dict`.
 
 .. seealso::
 
diff --git a/Misc/NEWS.d/next/Documentation/2020-02-19-11-13-47.bpo-17422.g7_9zz.rst b/Misc/NEWS.d/next/Documentation/2020-02-19-11-13-47.bpo-17422.g7_9zz.rst
new file mode 100644
index 0000000000000..f071d286176ae
--- /dev/null
+++ b/Misc/NEWS.d/next/Documentation/2020-02-19-11-13-47.bpo-17422.g7_9zz.rst
@@ -0,0 +1 @@
+The language reference now specifies restrictions on class namespaces.  Adapted from a patch by Ethan Furman.



More information about the Python-checkins mailing list