Skip to content

False negative for undefined-variable when attempting to access class scope from comprehension #3494

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
anjsimmo opened this issue Apr 20, 2020 · 0 comments · Fixed by #3497

Comments

@anjsimmo
Copy link
Contributor

Steps to reproduce

Consider the following example from the Python execution model reference here:

class A:
    a = 42
    b = list(a + i for i in range(10))

As per Python's documentation, executing this file will fail with the message NameError: name 'a' is not defined. (The class attribute a is considered out of scope from within the body of the generator expression. As of Python3, it would also be out of scope from within the body of a list comprehension.)

Current behavior

Pylint assumes that the class attribute a is visible from within the generator expression, and doesn't give a warning (i.e. a false negative).

Expected behavior

Pylint should print an undefined-variable warning when attempting to access class attributes from within the body of a generator expression or comprehension.

pylint --version output

pylint 2.4.4
astroid 2.3.3
Python 3.7.3 (default, Mar 27 2019, 22:11:17) 
[GCC 7.3.0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant