Python Glossary Русский

Python 3.7+typesfunction

types.resolve_bases()

dynamic class creation

Replaces bases that define __mro_entries__ with real classes — as the class statement does with a base such as Generic[T] or List[int].

Syntax

types.resolve_bases(bases)

An annotation such as typing.List[int] is not a class, and type() would refuse it as a base. The class statement quietly calls its __mro_entries__ and inherits from list and Generic. resolve_bases shows that substitution: the result is the real __bases__. It is for people writing their own class factories on top of type().

Examples

import types
import typing
print(types.resolve_bases((typing.List[int],)))
# → (<class 'list'>, <class 'typing.Generic'>)

See also

Open in the full glossarydocs.python.orgReport an inaccuracy