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.
This commit is contained in:
ananthan-123 2020-02-22 23:26:02 +05:30 committed by GitHub
parent 1c56f8ffad
commit fbe2e0bb8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View 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 is prepared. If the metaclass has a ``__prepare__`` attribute, it is called
as ``namespace = metaclass.__prepare__(name, bases, **kwds)`` (where the as ``namespace = metaclass.__prepare__(name, bases, **kwds)`` (where the
additional keyword arguments, if any, come from the class definition). 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 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:: .. seealso::

View File

@ -0,0 +1 @@
The language reference now specifies restrictions on class namespaces. Adapted from a patch by Ethan Furman.