Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(158447)

Unified Diff: Doc/reference/datamodel.rst

Issue 23722: During metaclass.__init__, super() of the constructed class does not work
Patch Set: Created 3 years ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Doc/whatsnew/3.6.rst » ('j') | Python/bltinmodule.c » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Doc/reference/datamodel.rst Sat Dec 03 15:57:00 2016 -0800
+++ b/Doc/reference/datamodel.rst Sun Dec 04 22:38:04 2016 +1000
@@ -1796,6 +1796,27 @@
lexical scoping, while the class or instance that was used to make the
current call is identified based on the first argument passed to the method.
+.. impl-detail::
+
+ In CPython 3.6 and later, the ``__class__`` cell is passed to the metaclass
+ as a ``__classcell__`` entry in the class namespace. If present, this must
+ be propagated up to the ``type.__new__`` call in order for the class to be
+ initialised correctly.
+
+ Failing to do so will result in a :exc:`DeprecationWarning` in Python 3.6,
+ and a :exc:`RuntimeWarning` in the future.
+
+When using the default metaclass :class:`type`, or any metaclass that ultimately
+calls ``type.__new__``, the following additional customisation steps are
+invoked after creating the class object:
+
+* first, ``type.__new__`` collects all of the descriptors in the class
+ namespace that define a ``__set_name__`` method
+* second, all of these ``__set_name__`` methods are called with the class
+ being defined and the assigned name of that particular descriptor
+* finally, the ``__init_subclass__`` hook is called on the immediate parent of
+ the new class in its method resolution order
+
After the class object is created, it is passed to the class decorators
included in the class definition (if any) and the resulting object is bound
in the local namespace as the defined class.
« no previous file with comments | « no previous file | Doc/whatsnew/3.6.rst » ('j') | Python/bltinmodule.c » ('J')

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+