Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -1959,6 +1959,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
Original file line number Diff line number Diff line change
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]])