You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Undefined comprehension variable in class body not caught #503
Pyflakes gives no errors here. But believe it or not, this raises a NameError
Traceback (most recent call last):
File "test.py", line 1, in <module>
class Test:
File "test.py", line 4, in Test
c = [i*j for i in a for j in b]
File "test.py", line 4, in <listcomp>
c = [i*j for i in a for j in b]
NameError: name 'b' is not defined
$python test.py
Traceback (most recent call last):
File "test.py", line 6, in <module>
class Test2:
File "test.py", line 8, in Test2
a = [x for i in range(2)]
File "test.py", line 8, in <listcomp>
a = [x for i in range(2)]
NameError: name 'x' is not defined
Activity
asmeurer commentedon Jan 10, 2020
Actually it doesn't even catch the simpler case
asottile commentedon Jan 10, 2020
pretty sure pyflakes doesn't know at all about the ~special
classscope -- but probably wouldn't be too difficult to addasmeurer commentedon Jan 10, 2020
It gets it right for normal nested functions (i.e., methods)