diff -r d84c1b42a8f3 Doc/reference/datamodel.rst --- a/Doc/reference/datamodel.rst Sat Dec 03 15:57:00 2016 -0800 +++ b/Doc/reference/datamodel.rst Sun Dec 04 17:26:21 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. diff -r d84c1b42a8f3 Doc/whatsnew/3.6.rst --- a/Doc/whatsnew/3.6.rst Sat Dec 03 15:57:00 2016 -0800 +++ b/Doc/whatsnew/3.6.rst Sun Dec 04 17:26:21 2016 +1000 @@ -351,6 +351,10 @@ class Plugin2(PluginBase): pass +In order to allow zero-argument :func:`super` calls to work correctly from +``__init_subclass__`` implementations, custom metaclasses must ensure that +the new ``__classcell__`` namespace entry is propagated to ``type.__new__``. + .. seealso:: :pep:`487` -- Simpler customization of class creation @@ -2235,6 +2239,11 @@ on a ZipFile created with mode ``'r'`` will raise a :exc:`ValueError`. Previously, a :exc:`RuntimeError` was raised in those scenarios. +* when custom metaclasses are combined with zero-argument :func:`super` or + direct references from methods to the implicit ``__class__`` closure + variable, the implicit ``__classcell__`` namespace entry must now be passed + up to ``type.__new__`` for initialisation. Failing to do so will result in + a :exc:`DeprecationWarning` in 3.6 and a :exc:`RuntimeWarning` in the future. Changes in the C API --------------------