Skip to content
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

name resolution in class-level list comprehension (python 2) #5708

Closed
bwo opened this issue Oct 1, 2018 · 1 comment
Closed

name resolution in class-level list comprehension (python 2) #5708

bwo opened this issue Oct 1, 2018 · 1 comment
Labels
bug mypy got something wrong priority-2-low topic-python2 issues only applicable to Python 2

Comments

@bwo
Copy link
Contributor

bwo commented Oct 1, 2018

This code is legal in Python 2:

class A(object):
    x = 1
    y = [x + 1 for _ in range(10)]

It seems not to be legal in Python 3.

However, even with -2, mypy does not allow it:

~/src 12:38:46 $ python3 foo.py
Traceback (most recent call last):
  File "foo.py", line 1, in <module>
    class A(object):
  File "foo.py", line 3, in A
    y = [x + 1 for _ in range(10)]
  File "foo.py", line 3, in <listcomp>
    y = [x + 1 for _ in range(10)]
NameError: name 'x' is not defined
~/src 12:38:55 $ python foo.py
~/src 12:38:57 $ mypy -2 foo.py
foo.py:3: error: Name 'x' is not defined

Expected behavior: the code should typecheck in py2 mode.

ETA: version 0.550; apologies if this is fixed. (Confirmed on 0.630.)

@ilevkivskyi ilevkivskyi added bug mypy got something wrong priority-2-low labels Jan 14, 2019
@AlexWaygood AlexWaygood added the topic-python2 issues only applicable to Python 2 label Mar 25, 2022
@JukkaL
Copy link
Collaborator

JukkaL commented Mar 31, 2022

Closing due to Python 2 feature freeze (#12237).

@JukkaL JukkaL closed this as completed Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-2-low topic-python2 issues only applicable to Python 2
Projects
None yet
Development

No branches or pull requests

4 participants