gh-103373: Improve documentation for `__mro_entries__` (#103374)

This commit is contained in:
Alex Waygood 2023-04-08 15:09:00 +01:00 committed by GitHub
parent b22d021ee6
commit 0ba0ca05d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 5 deletions

View File

@ -2086,11 +2086,15 @@ When a class definition is executed, the following steps occur:
Resolving MRO entries Resolving MRO entries
^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^
If a base that appears in class definition is not an instance of :class:`type`, .. method:: object.__mro_entries__(self, bases)
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 If a base that appears in a class definition is not an instance of
will be used instead of this base. The tuple may be empty, in such case :class:`type`, then an ``__mro_entries__`` method is searched on the base.
the original base is ignored. If an ``__mro_entries__`` method is found, the base is substituted with the
result of a call to ``__mro_entries__`` when creating the class.
The method is called with the original bases tuple, and must return a tuple
of classes that will be used instead of the base. The returned tuple may be
empty: in these cases, the original base is ignored.
.. seealso:: .. seealso::