Skip to content

Disallow isinstance of generic expressions #2373

Closed

Description

@ddfisher

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.)

Activity

  1. ilevkivskyi commented on Nov 8, 2016

    @ilevkivskyi
    Member

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

  2. ddfisher commented on Nov 8, 2016

    @ddfisher
    CollaboratorAuthor

    But mypy still doesn't give an error!

  3. added this to the milestone on Nov 8, 2016
  4. gvanrossum commented on Nov 8, 2016

    @gvanrossum
    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.)

  5. removed this from the milestone on Mar 29, 2017
  6. ilevkivskyi commented on Aug 23, 2017

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions