diff options
author | Ivan Levkivskyi <levkivskyi@gmail.com> | 2018-05-08 18:38:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-08 18:38:41 (GMT) |
commit | bd5f96581bf23f6d05fc106996428a8043b6b084 (patch) | |
tree | 4472cc045ee07777a8c7314fff24835a911cc856 /Doc/reference/datamodel.rst | |
parent | ec1622d56c80d15740f7f8459c9a79fd55f5d3c7 (diff) | |
download | cpython-bd5f96581bf23f6d05fc106996428a8043b6b084.zip cpython-bd5f96581bf23f6d05fc106996428a8043b6b084.tar.gz cpython-bd5f96581bf23f6d05fc106996428a8043b6b084.tar.bz2 |
bpo-32717: Document PEP 560 (GH-6726)
Diffstat (limited to 'Doc/reference/datamodel.rst')
-rw-r--r-- | Doc/reference/datamodel.rst | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 1e93ef4..b4a0dbf 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1857,11 +1857,27 @@ passed through to all metaclass operations described below. When a class definition is executed, the following steps occur: +* MRO entries are resolved * the appropriate metaclass is determined * the class namespace is prepared * the class body is executed * the class object is created + +Resolving MRO entries +^^^^^^^^^^^^^^^^^^^^^ + +If a base that appears in class definition is not an instance of :class:`type`, +then an ``__mro_entries__`` method is searched on it. If found, it is called +with the original bases tuple. This method must return a tuple of classes that +will be used instead of this base. The tuple may be empty, in such case +the original base is ignored. + +.. seealso:: + + :pep:`560` - Core support for typing module and generic types + + Determining the appropriate metaclass ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. index:: @@ -2061,6 +2077,27 @@ case the instance is itself a class. module) to the language. +Emulating generic types +----------------------- + +One can implement the generic class syntax as specified by :pep:`484` +(for example ``List[int]``) by defining a special method + +.. classmethod:: object.__class_getitem__(cls, key) + + Return an object representing the specialization of a generic class + by type arguments found in *key*. + +This method is looked up on the class object itself, and when defined in +the class body, this method is implicitly a class method. Note, this +mechanism is primarily reserved for use with static type hints, other usage +is discouraged. + +.. seealso:: + + :pep:`560` - Core support for typing module and generic types + + .. _callable-types: Emulating callable objects |