Skip to content

Commit

Permalink
Fix crash in unnecessary-list-index-lookup checker (pylint-dev#6049)
Browse files Browse the repository at this point in the history
  • Loading branch information
timmartin committed Mar 30, 2022
1 parent 789a381 commit a40cae9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pylint/checkers/refactoring/refactoring_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1994,6 +1994,11 @@ def _check_unnecessary_list_index_lookup(
# enumerate() result is being assigned without destructuring
return

if not isinstance(node.target.elts[1], nodes.AssignName):
# The value is not being assigned to a single variable, e.g. being
# destructured, so we can't necessarily use it.
return

iterating_object_name = node.iter.args[0].name
value_variable = node.target.elts[1]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,8 @@ def process_list_again(data):
result = [val for idx, val in enumerate(my_list) if idx > 0 and my_list[idx - 1] == 'a']
result = [val for idx, val in enumerate(my_list) if other_list[idx] == 'a']
result = [my_list[idx] for idx, val in enumerate(my_list)] # [unnecessary-list-index-lookup]

# Issue #6409
pairs = [(0, 0)]
for i, (a, b) in enumerate(pairs):
print(pairs[i][0])

0 comments on commit a40cae9

Please sign in to comment.