Skip to content

Commit

Permalink
Fix a crash in unnecessary-list-index-lookup when incorrectly using…
Browse files Browse the repository at this point in the history
… `enumerate()` (#6604)
  • Loading branch information
jacobtylerwalls committed May 13, 2022
1 parent 55cacdb commit 5fee33f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Expand Up @@ -344,6 +344,11 @@ Release date: TBA

Closes #6557

* Fix a crash in ``unnecessary-list-index-lookup`` when incorrectly passing no
arguments to ``enumerate()``.

Closes #6603

* Fix a crash when accessing ``__code__`` and assigning it to a variable.

Closes #6539
Expand Down
4 changes: 4 additions & 0 deletions doc/whatsnew/2.13.rst
Expand Up @@ -644,6 +644,10 @@ Other Changes

Closes #6414

* Fix a crash in ``unnecessary-list-index-lookup`` when incorrectly passing no
arguments to ``enumerate()``.

Closes #6603

* Fix false positives for ``no-name-in-module`` and ``import-error`` for ``numpy.distutils``
and ``pydantic``.
Expand Down
1 change: 1 addition & 0 deletions pylint/checkers/refactoring/refactoring_checker.py
Expand Up @@ -1996,6 +1996,7 @@ def _check_unnecessary_list_index_lookup(
not isinstance(node.iter, nodes.Call)
or not isinstance(node.iter.func, nodes.Name)
or not node.iter.func.name == "enumerate"
or not node.iter.args
or not isinstance(node.iter.args[0], nodes.Name)
):
return
Expand Down
Expand Up @@ -49,3 +49,7 @@ def process_list_again(data):
pairs = [(0, 0)]
for i, (a, b) in enumerate(pairs):
print(pairs[i][0])

# Regression test for https://github.com/PyCQA/pylint/issues/6603
for i, num in enumerate(): # raises TypeError, but shouldn't crash pylint
pass

0 comments on commit 5fee33f

Please sign in to comment.