Skip to content

isinstance + generator results in unexpected error #1044

Closed
@JukkaL

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.

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