Skip to content

Commit af3816b

Browse files
jacobtylerwallsPierre-Sassoulas
authored andcommitted
Avoid raising undefined-loop-variable twice on same line (#6925)
1 parent ffcdf42 commit af3816b

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

doc/whatsnew/2/2.14/full.rst

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ What's New in Pylint 2.14.2?
55
----------------------------
66
Release date: TBA
77

8+
* Avoided raising an identical ``undefined-loop-variable`` message twice on the same line.
9+
810
* Don't crash if ``lint.run._query_cpu()`` is run within a Kubernetes Pod, that has only
911
a fraction of a cpu core assigned. Just go with one process then.
1012

pylint/checkers/variables.py

-1
Original file line numberDiff line numberDiff line change
@@ -1499,7 +1499,6 @@ def _check_consumer(
14991499
node, nodes.ComprehensionScope
15001500
):
15011501
self._check_late_binding_closure(node)
1502-
self._loopvar_name(node)
15031502
return (VariableVisitConsumerAction.RETURN, None)
15041503

15051504
found_nodes = current_consumer.get_next_to_consume(node)

tests/functional/u/undefined/undefined_loop_variable.py

+8
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,11 @@ def use_enumerate():
146146
for i, num in enumerate(range(3)):
147147
pass
148148
print(i, num)
149+
150+
151+
def find_even_number(container):
152+
"""https://github.com/PyCQA/pylint/pull/6923#discussion_r895134495"""
153+
for something in container:
154+
if something % 2 == 0:
155+
break
156+
return something # [undefined-loop-variable]
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
undefined-loop-variable:6:11:6:14:do_stuff:Using possibly undefined loop variable 'var':UNDEFINED
22
undefined-loop-variable:25:7:25:11::Using possibly undefined loop variable 'var1':UNDEFINED
33
undefined-loop-variable:75:11:75:14:do_stuff_with_redefined_range:Using possibly undefined loop variable 'var':UNDEFINED
4+
undefined-loop-variable:156:11:156:20:find_even_number:Using possibly undefined loop variable 'something':UNDEFINED

0 commit comments

Comments
 (0)