Skip to content

Commit 36a120d

Browse files
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 fbe2e0b) Co-authored-by: ananthan-123 <ananthakrishnan15.2001@gmail.com>
1 parent 43a0137 commit 36a120d

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

Doc/reference/datamodel.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,10 +1932,12 @@ Once the appropriate metaclass has been identified, then the class namespace
19321932
is prepared. If the metaclass has a ``__prepare__`` attribute, it is called
19331933
as ``namespace = metaclass.__prepare__(name, bases, **kwds)`` (where the
19341934
additional keyword arguments, if any, come from the class definition). The
1935-
``__prepare__`` method should be implemented as a :func:`classmethod`.
1935+
``__prepare__`` method should be implemented as a :func:`classmethod`. The
1936+
namespace returned by ``__prepare__`` is passed in to ``__new__``, but when
1937+
the final class object is created the namespace is copied into a new ``dict``.
19361938

19371939
If the metaclass has no ``__prepare__`` attribute, then the class namespace
1938-
is initialised as an empty ordered mapping.
1940+
is initialised as an empty :func:`dict`.
19391941

19401942
.. seealso::
19411943

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The language reference now specifies restrictions on class namespaces. Adapted from a patch by Ethan Furman.

0 commit comments

Comments
 (0)