Skip to content

isinstance + generator results in unexpected error #1044

Closed

Description

@JukkaL

This code doesn't generate errors:

class A:
    y = False
a = None # type: object
(a.y for a in [A()])

However, this generates (just added isinstance):

class A:
    y = False
a = None # type: object
if isinstance(a, int): pass   # only difference
(a.y for a in [A()])

Output is like this:

program.py:7: error: "object" has no attribute "y"

The latter program shouldn't generate any error. There seems to be some weird interaction between isinstance and generator scoping.

Activity

  1. JukkaL commented on Dec 4, 2015

    @JukkaL
    CollaboratorAuthor

    Ah, the type in the conditional type binder probably gets propagated to the generator even though that variable there is in a different scope.

  2. emmatyping commented on Jul 6, 2017

    @emmatyping
    Member

    The second example works fine at least in 0.510, so Im closing this.

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

    bugmypy got something wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions