Skip to content

Prohibit parameterized generics in isinstance #3037

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

Closed
pkch opened this issue Mar 20, 2017 · 1 comment
Closed

Prohibit parameterized generics in isinstance #3037

pkch opened this issue Mar 20, 2017 · 1 comment
Labels

Comments

@pkch
Copy link
Contributor

pkch commented Mar 20, 2017

As @ilevkivskyi commented (#3005 (comment)), it would be nice to fail type check on this code:

obj = 1
if isinstance(obj, Iterable[int]):
    1

because it fails in runtime with TypeError.

I can easily see this situation inside checker.py:get_isinstance_type() by verifying that len(type.items()[0].ret_type.args) == 0; but is it the right place to message about type validation problems?

@ilevkivskyi
Copy link
Member

Maybe the right place is in visit_call_expr in checkexpr.py? If the name of function called is builtins.isinstance or builtins.issubclass and there is, for example, any CallableType argument with .is_class_obj() returning True and having type arguments, then you issue a warning.

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

No branches or pull requests

2 participants