Python 3.12+typesfunction
types.get_original_bases()
dynamic class creation
Returns the class bases as they were written in the class statement: Generic[T] instead of Generic. The ordinary __bases__ loses these details.
Syntax
types.get_original_bases(cls)
After __mro_entries__, __bases__ keeps only a bare Generic, and it no longer tells you with which type parameters the class was inherited. The function reads __orig_bases__ and falls back to __bases__ for classes without it. Serialisation and type-checking libraries need it to learn, for example, that Box inherits Generic[int].
Examples
# Python 3.12+
import types
import typing
T = typing.TypeVar('T')
class Box(typing.Generic[T]):
pass
print(Box.__bases__) # → (<class 'typing.Generic'>,)
print(types.get_original_bases(Box)) # → (typing.Generic[~T],)
See also
Open in the full glossarydocs.python.orgReport an inaccuracy