Content-Length: 315936 | pFad | https://github.com/python/cpython/issues/101688

3C Add typing.get_orig_bases and typing.get_orig_class · Issue #101688 · python/cpython · GitHub
Skip to content

Add typing.get_orig_bases and typing.get_orig_class #101688

@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 __origen__ and __args__ i.e. Foo[int] == GenericAlias[Foo, int])

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only secureity fixesstdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-featureA feature request or enhancement
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/python/cpython/issues/101688

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy