mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-32717: Document PEP 560 (GH-6726)
This commit is contained in:
parent
ec1622d56c
commit
bd5f96581b
3 changed files with 74 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue