summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2022-06-12 11:08:01 -0400
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2022-06-15 08:43:02 +0200
commitaf3816bea19756ed91305a3c01ebc68b0b3b8b2b (patch)
tree3cdc98789862c97b0b5794007685390481fb8ec5
parentffcdf429fbf9ebd109a3bf9b2d3eecb9c8a0fe72 (diff)
downloadpylint-git-af3816bea19756ed91305a3c01ebc68b0b3b8b2b.tar.gz
Avoid raising `undefined-loop-variable` twice on same line (#6925)
-rw-r--r--doc/whatsnew/2/2.14/full.rst2
-rw-r--r--pylint/checkers/variables.py1
-rw-r--r--tests/functional/u/undefined/undefined_loop_variable.py8
-rw-r--r--tests/functional/u/undefined/undefined_loop_variable.txt1
4 files changed, 11 insertions, 1 deletions
diff --git a/doc/whatsnew/2/2.14/full.rst b/doc/whatsnew/2/2.14/full.rst
index 4e9bbc539..71e692fb6 100644
--- a/doc/whatsnew/2/2.14/full.rst
+++ b/doc/whatsnew/2/2.14/full.rst
@@ -5,6 +5,8 @@ What's New in Pylint 2.14.2?
----------------------------
Release date: TBA
+* Avoided raising an identical ``undefined-loop-variable`` message twice on the same line.
+
* Don't crash if ``lint.run._query_cpu()`` is run within a Kubernetes Pod, that has only
a fraction of a cpu core assigned. Just go with one process then.
diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py
index 839558523..7eeb1e854 100644
--- a/pylint/checkers/variables.py
+++ b/pylint/checkers/variables.py
@@ -1499,7 +1499,6 @@ class VariablesChecker(BaseChecker):
node, nodes.ComprehensionScope
):
self._check_late_binding_closure(node)
- self._loopvar_name(node)
return (VariableVisitConsumerAction.RETURN, None)
found_nodes = current_consumer.get_next_to_consume(node)
diff --git a/tests/functional/u/undefined/undefined_loop_variable.py b/tests/functional/u/undefined/undefined_loop_variable.py
index fc8640f7a..a4249a39f 100644
--- a/tests/functional/u/undefined/undefined_loop_variable.py
+++ b/tests/functional/u/undefined/undefined_loop_variable.py
@@ -146,3 +146,11 @@ def use_enumerate():
for i, num in enumerate(range(3)):
pass
print(i, num)
+
+
+def find_even_number(container):
+ """https://github.com/PyCQA/pylint/pull/6923#discussion_r895134495"""
+ for something in container:
+ if something % 2 == 0:
+ break
+ return something # [undefined-loop-variable]
diff --git a/tests/functional/u/undefined/undefined_loop_variable.txt b/tests/functional/u/undefined/undefined_loop_variable.txt
index 9157e4195..ef9031c57 100644
--- a/tests/functional/u/undefined/undefined_loop_variable.txt
+++ b/tests/functional/u/undefined/undefined_loop_variable.txt
@@ -1,3 +1,4 @@
undefined-loop-variable:6:11:6:14:do_stuff:Using possibly undefined loop variable 'var':UNDEFINED
undefined-loop-variable:25:7:25:11::Using possibly undefined loop variable 'var1':UNDEFINED
undefined-loop-variable:75:11:75:14:do_stuff_with_redefined_range:Using possibly undefined loop variable 'var':UNDEFINED
+undefined-loop-variable:156:11:156:20:find_even_number:Using possibly undefined loop variable 'something':UNDEFINED