If I initialize the list, l, to anything besides the empty list, then the W0631 warning goes away. Or instead if I delete the second for-loop, the W0631 warning goes away as well.
% pylint test.py
************* Module test
test.py:16:25: W0640: Cell variable thing defined in loop (cell-var-from-loop)
test.py:16:25: W0631: Using possibly undefined loop variable 'thing' (undefined-loop-variable)
-----------------------------------
Your code has been rated at 8.46/10
Expected behavior
I don't expect to see W0631 (undefined-loop-variable). The (cell-var-from-loop) warning is warranted.
Pylint version
% pylint --version
pylint 2.11.1
astroid 2.8.5
Python 3.8.12 (default, Aug 31 2021, 12:46:19)
[GCC 8.4.0 20200304 (Red Hat 8.4.0-4)]
OS / Environment
No response
Additional dependencies
No response
The text was updated successfully, but these errors were encountered:
Thanks, I agree that's unexpected. This diff seems to fix it. If this looks correct to you, would you perhaps be interested in submitting a PR?
collapsed bc this wasn't correct, entirely
```diff
diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py
index 1a84b739..16c93c41 100644
--- a/pylint/checkers/variables.py
+++ b/pylint/checkers/variables.py
@@ -2222,8 +2222,8 @@ class VariablesChecker(BaseChecker):
):
_astmts = []
else:
- _astmts = astmts[:1]
- for i, stmt in enumerate(astmts[1:]):
+ _astmts = astmts[:]
+ for i, stmt in enumerate(astmts):
if astmts[i].statement(future=True).parent_of(
stmt
) and not in_for_else_branch(astmts[i].statement(future=True), stmt):
```
jacobtylerwalls
changed the title
W0631 undefined-loop-variable false positive
W0631 undefined-loop-variable false positive for lambda statements inside first of two loops
Apr 21, 2022
Bug description
If I initialize the list, l, to anything besides the empty list, then the W0631 warning goes away. Or instead if I delete the second for-loop, the W0631 warning goes away as well.
Seems similar to this bug: #202
Configuration
No response
Command used
Pylint output
Expected behavior
I don't expect to see W0631 (undefined-loop-variable). The (cell-var-from-loop) warning is warranted.
Pylint version
OS / Environment
No response
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: