Closed
Description
Feature or enhancement
typing has had type.__orig_bases__
and type.__orig_class__
for quite some time now, there is no stable API to access these attributes.
Pitch
I would like to propose adding typing.get_orig_bases
as something like
@overload
def get_orig_bases(cls: type[object]) -> tuple[type[Any], ...] | None: ...
@overload
def get_orig_bases(cls: Any) -> None: ...
def get_orig_bases(cls: Any) -> tuple[type[Any], ...] | None:
return getattr(cls, "__orig_bases__", None)
and typing.get_orig_class
@overload
def get_orig_class(cls: type[object]) -> GenericAlias | None: ...
@overload
def get_orig_class(cls: Any) -> None: ...
def get_orig_class(cls: Any) -> GenericAlias | None:
return getattr(cls, "__orig_class__", None)
(side note, it might be possible to fully type get_orig_class
it types.GenericAlias
was generic over the __origin__
and __args__
i.e. Foo[int] == GenericAlias[Foo, int]
)
Linked PRs
Metadata
Metadata
Assignees
Labels
only security fixesonly security fixesPython modules in the Lib dirPython modules in the Lib dirA feature request or enhancementA feature request or enhancement