[Python-checkins] cpython: Issue 27366: PEP 487 docs updates

nick.coghlan python-checkins at python.org
Sat Jul 30 22:43:03 EDT 2016


https://hg.python.org/cpython/rev/313e8fdb0d0c
changeset:   102498:313e8fdb0d0c
user:        Nick Coghlan <ncoghlan at gmail.com>
date:        Sun Jul 31 12:42:49 2016 +1000
summary:
  Issue 27366: PEP 487 docs updates

- Porting note for type keyword arg handling
- __init_subclass__ note regarding  metaclass hint

files:
  Doc/reference/datamodel.rst |  7 +++++++
  Doc/whatsnew/3.6.rst        |  9 +++++++++
  2 files changed, 16 insertions(+), 0 deletions(-)


diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst
--- a/Doc/reference/datamodel.rst
+++ b/Doc/reference/datamodel.rst
@@ -1672,6 +1672,13 @@
    The default implementation ``object.__init_subclass__`` does
    nothing, but raises an error if it is called with any arguments.
 
+   .. note::
+
+      The metaclass hint ``metaclass`` is consumed by the rest of the type
+      machinery, and is never passed to ``__init_subclass__`` implementations.
+      The actual metaclass (rather than the explicit hint) can be accessed as
+      ``type(cls)``.
+
    .. versionadded:: 3.6
 
 
diff --git a/Doc/whatsnew/3.6.rst b/Doc/whatsnew/3.6.rst
--- a/Doc/whatsnew/3.6.rst
+++ b/Doc/whatsnew/3.6.rst
@@ -759,6 +759,15 @@
   <keyword-only_parameter>`.
   (Contributed by Serhiy Storchaka in :issue:`18726`.)
 
+* As part of :pep:`487`, the handling of keyword arguments passed to
+  :class:`type` (other than the metaclass hint, ``metaclass``) is now
+  consistently delegated to :meth:`object.__init_subclass__`. This means that
+  :meth:`type.__new__` and :meth:`type.__init__` both now accept arbitrary
+  keyword arguments, but :meth:`object.__init_subclass__` (which is called from
+  :meth:`type.__new__`) will reject them by default. Custom metaclasses
+  accepting additional keyword arguments will need to adjust their calls to
+  :meth:`type.__new__` (whether direct or via :class:`super`) accordingly.
+
 
 Changes in the C API
 --------------------

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list