Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_origin() doesn't support PEP 585 generic types? #89

Open
rouge8 opened this issue Jul 25, 2022 · 2 comments
Open

get_origin() doesn't support PEP 585 generic types? #89

rouge8 opened this issue Jul 25, 2022 · 2 comments

Comments

@rouge8
Copy link

rouge8 commented Jul 25, 2022

Hi,

I'm seeing different behavior with get_origin(typing.List) and get_origin(list):

[ins] In [1]: from typing_extensions import get_origin

[ins] In [2]: import typing

[ins] In [3]: get_origin(list[int])
Out[3]: list

[ins] In [4]: get_origin(list)

[ins] In [5]: get_origin(typing.List)
Out[5]: list
@rtbs-dev
Copy link

rtbs-dev commented Aug 2, 2022

This is what I'm running into as well. I would like to be able to work around the fact that e.g. typing.Sequence.mro() will give me a sane list of the type hierarchy, but list is jumping directly to object (after pep 585), even though issubclass(list, typing.Sequence) is True.

I realize why this is happening, but I am here because I thought typing_inspect gave a workaround to access the actual type hierarchy here. I don't want to pairwise check whether or not type H is a subclass of G, Y, and A, but would much prefer to get a list of everything in the base library list is known a priori to pass a typecheck on! 😅

@ilevkivskyi
Copy link
Owner

IIUC this behavior matches get_origin() from typing itself, right (for versions where it is available)? Also changing this would be backwards incompatible, so I am not sure we should do this.

In any case, a simple workaround is to keep a map list -> List, dict -> Dict etc. (there are very few builtin collections that are actually generic), and then call get_origin() again on the typing version if the first call returned something in this map.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants