Skip to content

Commit fbe2e0b

Browse files
authored
bpo-17422: Language reference should specify restrictions on class namespace (#18559)
The language reference now specifies restrictions on class namespaces. Adapted from a patch by Ethan Furman.
1 parent 1c56f8f commit fbe2e0b

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
@@ -1946,10 +1946,12 @@ Once the appropriate metaclass has been identified, then the class namespace
19461946
is prepared. If the metaclass has a ``__prepare__`` attribute, it is called
19471947
as ``namespace = metaclass.__prepare__(name, bases, **kwds)`` (where the
19481948
additional keyword arguments, if any, come from the class definition). The
1949-
``__prepare__`` method should be implemented as a :func:`classmethod`.
1949+
``__prepare__`` method should be implemented as a :func:`classmethod`. The
1950+
namespace returned by ``__prepare__`` is passed in to ``__new__``, but when
1951+
the final class object is created the namespace is copied into a new ``dict``.
19501952

19511953
If the metaclass has no ``__prepare__`` attribute, then the class namespace
1952-
is initialised as an empty ordered mapping.
1954+
is initialised as an empty :func:`dict`.
19531955

19541956
.. seealso::
19551957

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)