Clarify the distinction between the definition ns and __dict__.
This commit is contained in:
parent
97e820b228
commit
4f37f47475
10
pep-0520.txt
10
pep-0520.txt
|
@ -14,15 +14,19 @@ Post-History: 7-Jun-2016
|
||||||
Abstract
|
Abstract
|
||||||
========
|
========
|
||||||
|
|
||||||
|
When a class is defined using a ``class`` statement, the class body is
|
||||||
|
executed within a namespace. After the execution completes, that
|
||||||
|
namespace is copied into new ``dict`` and the original definition
|
||||||
|
namespace is discarded. The new copy is stored away as the class's
|
||||||
|
namespace and is exposed as ``__dict__`` through a read-only proxy.
|
||||||
|
|
||||||
This PEP changes the default class definition namespace to ``OrderedDict``.
|
This PEP changes the default class definition namespace to ``OrderedDict``.
|
||||||
|
The long-lived class namespace (``__dict__``) will remain a ``dict``.
|
||||||
Furthermore, the order in which the attributes are defined in each class
|
Furthermore, the order in which the attributes are defined in each class
|
||||||
body will now be preserved in the ``__definition_order__`` attribute of
|
body will now be preserved in the ``__definition_order__`` attribute of
|
||||||
the class. This allows introspection of the original definition order,
|
the class. This allows introspection of the original definition order,
|
||||||
e.g. by class decorators.
|
e.g. by class decorators.
|
||||||
|
|
||||||
Note: just to be clear, this PEP is *not* about changing ``__dict__`` for
|
|
||||||
classes to ``OrderedDict``.
|
|
||||||
|
|
||||||
|
|
||||||
Motivation
|
Motivation
|
||||||
==========
|
==========
|
||||||
|
|
Loading…
Reference in New Issue