Skip to content

Comprehension in class scope should see class variables #1000

Closed
@gvanrossum

Description

@gvanrossum

Example:

class C:
    A = 'abc'
    B = [c for c in A]

This is valid Python code, but mypy doesn't believe that A exists. (Note that it's specific to comprehensions and generator expressions -- if I put a plain C = A.lower() there it works fine.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongfalse-positivemypy gave an error on correct codepriority-2-lowtopic-python2issues only applicable to Python 2topic-runtime-semanticsmypy doesn't model runtime semantics correctly

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions