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

Add a simple is_type(t) method #67

Open
gpshead opened this issue Feb 13, 2021 · 2 comments
Open

Add a simple is_type(t) method #67

gpshead opened this issue Feb 13, 2021 · 2 comments

Comments

@gpshead
Copy link

gpshead commented Feb 13, 2021

It should determine if t is meaningful to use in an isinstance check.

We've got some code in 3.6 that was simply doing:

isinstance(t, type)

for this purpose. It worked. typing.List as well as all your basic types passed correctly.

It blows up in 3.7 onwards because the type of typing.List and friends has changed from type to typing._GenericAlias or typing._SpecialGenericAlias.

Not having a simple way to answer the question of is something is a type that is meaningfully usable for isinstance checks from other things is frustrating. (I'd argue that such a basic thing should even go in the Python stdlib, but this module may be the best playground for that to start in)

@ilevkivskyi
Copy link
Owner

Yeah, this would be a reasonable thing to have. I will not have time to add it myself (and polish possible corner cases), but PRs are welcome.

@mitar
Copy link

mitar commented Sep 27, 2021

I currently use isinstance(obj, type) or isinstance(obj, typing_inspect.typingGenericAlias).

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