diff options
| author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2018-05-08 11:52:36 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-05-08 11:52:36 -0700 |
| commit | 101d0d585f99a3b8c8d070b9d4dea15fa3daff62 (patch) | |
| tree | beeff689e04c4712e1ed859a654a74f95fd3befa /Doc/reference | |
| parent | 6049bda21b607acc90bbabcc604997e794e8aee1 (diff) | |
| download | cpython-git-101d0d585f99a3b8c8d070b9d4dea15fa3daff62.tar.gz | |
bpo-32717: Document PEP 560 (GH-6726)
(cherry picked from commit bd5f96581bf23f6d05fc106996428a8043b6b084)
Co-authored-by: Ivan Levkivskyi <levkivskyi@gmail.com>
Diffstat (limited to 'Doc/reference')
| -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 1e93ef4594..b4a0dbf95e 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 |
