]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-17422: Language reference should specify restrictions on class namespace (#18559)
authorananthan-123 <ananthakrishnan15.2001@gmail.com>
Sat, 22 Feb 2020 17:56:02 +0000 (23:26 +0530)
committerGitHub <noreply@github.com>
Sat, 22 Feb 2020 17:56:01 +0000 (09:56 -0800)
The language reference now specifies restrictions on class namespaces.  Adapted from a patch by Ethan Furman.

Doc/reference/datamodel.rst
Misc/NEWS.d/next/Documentation/2020-02-19-11-13-47.bpo-17422.g7_9zz.rst [new file with mode: 0644]

index 9520f824287f6b05ac10d732fbf6623d3573dc4f..5b3b669c5eb91f665d2dbdf82d7f18612ed73bce 100644 (file)
@@ -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.
+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 (file)
index 0000000..f071d28
--- /dev/null
@@ -0,0 +1 @@
+The language reference now specifies restrictions on class namespaces.  Adapted from a patch by Ethan Furman.