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

cell-var-from-loop misses case with nested loop #2846

Closed
ghost opened this issue Mar 29, 2019 · 3 comments · Fixed by #4827
Closed

cell-var-from-loop misses case with nested loop #2846

ghost opened this issue Mar 29, 2019 · 3 comments · Fixed by #4827
Labels
Checkers Related to a checker Enhancement ✨ Improvement to a component
Milestone

Comments

@ghost
Copy link

ghost commented Mar 29, 2019

Steps to reproduce

  1. Create a file a.py containing:
TEST_A = [
    (lambda: n)
    for n in range(3)
]

TEST_B = [
    (lambda: [n for _ in range(3)])
    for n in range(3)
]

print(TEST_A[1]())  # User probably intended for this to be 1, actually 2

print(TEST_B[1]())  # User probably intended for this to be [1, 1, 1], actually [2, 2, 2]
  1. Run pylint a.py

Current behavior

There is a lint failure: a.py:2:13: W0640: Cell variable n defined in loop (cell-var-from-loop)
Tere is no such failure for TEST_B.

Expected behavior

Lint failures for both TEST_A and TEST_B.

pylint --version output

pylint 2.3.1
astroid 2.2.5
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 22:20:52) [MSC v.1916 32 bit (Intel)]
@PCManticore
Copy link
Contributor

Thanks for the report @andy-ms

@PCManticore PCManticore added Checkers Related to a checker Enhancement ✨ Improvement to a component labels Apr 3, 2019
@SamyCookie
Copy link

Does #2276 fixed this issue ?

@PCManticore
Copy link
Contributor

The error still seems to be here on master branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Checkers Related to a checker Enhancement ✨ Improvement to a component
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants