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

Disallow isinstance of generic expressions #2373

Closed
ddfisher opened this issue Oct 28, 2016 · 4 comments
Closed

Disallow isinstance of generic expressions #2373

ddfisher opened this issue Oct 28, 2016 · 4 comments
Labels
bug mypy got something wrong priority-1-normal

Comments

@ddfisher
Copy link
Collaborator

ddfisher commented Oct 28, 2016

Now that runtime generics are allowed (thanks to #2302), we should prevent people from making calls like:

isinstance(["foo"], List[int])

because it won't behave as expected. I.e. in this case, it will return True. (First instance of user confusion appeared in #2369.)

@ilevkivskyi
Copy link
Member

Latest version of typing.py raises TypeError for things like this. Only unsubscripted generics etc. are allowed with instance/class checks.

@ddfisher ddfisher reopened this Nov 8, 2016
@ddfisher
Copy link
Collaborator Author

ddfisher commented Nov 8, 2016

But mypy still doesn't give an error!

@gvanrossum gvanrossum added the bug mypy got something wrong label Nov 8, 2016
@gvanrossum gvanrossum added this to the 0.5 milestone Nov 8, 2016
@gvanrossum
Copy link
Member

Oops, sorry. Classified as bug for milestone 0.5. (Since it's a runtime error I don't think it's a very big deal if mypy doesn't catch it.)

@ilevkivskyi
Copy link
Member

This is fixed now, mypy says

error: Parameterized generics cannot be used with class or instance checks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-1-normal
Projects
None yet
Development

No branches or pull requests

3 participants