Skip to content

Add typing.get_orig_bases and typing.get_orig_class #101688

Closed
@Gobot1234

Description

@Gobot1234

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

No one assigned

    Labels

    3.12only security fixesstdlibPython modules in the Lib dirtopic-typingtype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions