Skip to content

isinstance + generator results in unexpected error #1044

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
JukkaL opened this issue Dec 4, 2015 · 2 comments
Closed

isinstance + generator results in unexpected error #1044

JukkaL opened this issue Dec 4, 2015 · 2 comments
Labels
bug mypy got something wrong

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Dec 4, 2015

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.

@JukkaL JukkaL added the bug mypy got something wrong label Dec 4, 2015
@JukkaL
Copy link
Collaborator Author

JukkaL commented Dec 4, 2015

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

@emmatyping
Copy link
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
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

3 participants