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
False positive for cell-var-from-loop #3107
Comments
Thanks for the report. |
PCManticore
changed the title
false positive cell-var-from-loop even with trick
False positive for cell-var-from-loop
Sep 23, 2019
handlers = []
for i in range(10):
handlers.append(lambda: i) |
This isn't a false positive, since In [1]: handlers = []
In [2]: for i in range(10):
...: handlers.append(lambda: i)
...:
In [3]: [h() for h in handlers]
Out[3]: [9, 9, 9, 9, 9, 9, 9, 9, 9, 9] |
Ouch, you're so right. My bad, bad example ! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Steps to reproduce
Current behavior
W0640: Cell variable i defined in loop (cell-var-from-loop)
Expected behavior
I would expect to avoid the warning because the "i" is passed as default argument to the lambda. I get the false positive also if I loop along objects instead of list.
But I don't get it for the code below (looping along ints)
pylint --version output
pylint 2.3.1
astroid 2.2.5
Python 3.7.4 (v3.7.4:e09359112e, Jul 8 2019, 14:54:52)
thanks
The text was updated successfully, but these errors were encountered: