Skip to content

Commit

Permalink
Avoid raising undefined-loop-variable twice on same line (#6925)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls authored and Pierre-Sassoulas committed Jun 15, 2022
1 parent ffcdf42 commit af3816b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions doc/whatsnew/2/2.14/full.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 0 additions & 1 deletion pylint/checkers/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,6 @@ def _check_consumer(
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)
Expand Down
8 changes: 8 additions & 0 deletions tests/functional/u/undefined/undefined_loop_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
1 change: 1 addition & 0 deletions tests/functional/u/undefined/undefined_loop_variable.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit af3816b

Please sign in to comment.