Skip to content

Commit

Permalink
Fix a crash in unnecessary-dict-index-lookup when subscripting an a…
Browse files Browse the repository at this point in the history
…ttribute (#6579)
  • Loading branch information
jacobtylerwalls authored and Pierre-Sassoulas committed May 13, 2022
1 parent aecadc2 commit 33f3fcf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Expand Up @@ -29,6 +29,10 @@ Release date: TBA

Relates to #6531

* Fix a crash in ``unnecessary-dict-index-lookup`` when subscripting an attribute.

Closes #6557

* 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 @@ -653,3 +653,7 @@ Other Changes
* Fix ``IndexError`` crash in ``uninferable_final_decorators`` method.

Relates to #6531

* Fix a crash in ``unnecessary-dict-index-lookup`` when subscripting an attribute.

Closes #6557
1 change: 1 addition & 0 deletions pylint/checkers/refactoring/refactoring_checker.py
Expand Up @@ -1938,6 +1938,7 @@ def _check_unnecessary_dict_index_lookup(
elif isinstance(value, nodes.Subscript):
if (
not isinstance(node.target, nodes.AssignName)
or not isinstance(value.value, nodes.Name)
or node.target.name != value.value.name
or iterating_object_name != subscript.value.as_string()
):
Expand Down
Expand Up @@ -112,3 +112,10 @@ class Foo:
d = {}
for key, in d.items():
print(d[key])

# Test subscripting an attribute
# https://github.com/PyCQA/pylint/issues/6557
f = Foo()
for input_output in d.items():
f.input_output = input_output # pylint: disable=attribute-defined-outside-init
print(d[f.input_output[0]])

0 comments on commit 33f3fcf

Please sign in to comment.