summaryrefslogtreecommitdiffstats
path: root/Doc/reference
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2016-09-05 21:50:11 (GMT)
committerEric Snow <ericsnowcurrently@gmail.com>2016-09-05 21:50:11 (GMT)
commit92a6c170e6897ee98c36a3a9087b1a7d3e054d2b (patch)
tree59cbc717ac59e802529bc3ad4e61de161b66ac68 /Doc/reference
parent45659861380a9cd9e41ea002d4de92519ffb3422 (diff)
downloadcpython-92a6c170e6897ee98c36a3a9087b1a7d3e054d2b.zip
cpython-92a6c170e6897ee98c36a3a9087b1a7d3e054d2b.tar.gz
cpython-92a6c170e6897ee98c36a3a9087b1a7d3e054d2b.tar.bz2
Issue #24254: Preserve class attribute definition order.
Diffstat (limited to 'Doc/reference')
-rw-r--r--Doc/reference/compound_stmts.rst11
-rw-r--r--Doc/reference/datamodel.rst9
2 files changed, 19 insertions, 1 deletions
diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst
index 1c5bbdf..2eab29a 100644
--- a/Doc/reference/compound_stmts.rst
+++ b/Doc/reference/compound_stmts.rst
@@ -632,6 +632,17 @@ list for the base classes and the saved local namespace for the attribute
dictionary. The class name is bound to this class object in the original local
namespace.
+The order in which attributes are defined in the class body is preserved
+in the ``__definition_order__`` attribute on the new class. If that order
+is not known then the attribute is set to :const:`None`. The class body
+may include a ``__definition_order__`` attribute. In that case it is used
+directly. The value must be a tuple of identifiers or ``None``, otherwise
+:exc:`TypeError` will be raised when the class statement is executed.
+
+.. versionchanged:: 3.6
+
+ Add ``__definition_order__`` to classes.
+
Class creation can be customized heavily using :ref:`metaclasses <metaclasses>`.
Classes can also be decorated: just like when decorating functions, ::
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst
index e7328ab..00785ed 100644
--- a/Doc/reference/datamodel.rst
+++ b/Doc/reference/datamodel.rst
@@ -1750,7 +1750,14 @@ as ``namespace = metaclass.__prepare__(name, bases, **kwds)`` (where the
additional keyword arguments, if any, come from the class definition).
If the metaclass has no ``__prepare__`` attribute, then the class namespace
-is initialised as an empty :func:`dict` instance.
+is initialised as an empty ordered mapping.
+
+.. impl-detail::
+
+ In CPython the default is :class:`collections.OrderedDict`.
+
+.. versionchanged:: 3.6
+ Defaults to :class:`collections.OrderedDict` instead of :func:`dict`.
.. seealso::