Skip to content

Prohibit parameterized generics in isinstance #3037

Closed

Description

@pkch

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?

Activity

  1. ilevkivskyi commented on Mar 20, 2017

    @ilevkivskyi
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions