File tree 4 files changed +19
-0
lines changed
pylint/checkers/refactoring
tests/functional/u/unnecessary
4 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,11 @@ Release date: TBA
25
25
26
26
Closes #4716
27
27
28
+ * Fix crash in ``unnecessary-dict-index-lookup`` checker if the output of
29
+ ``items()`` is assigned to a 1-tuple.
30
+
31
+ Closes #5504
32
+
28
33
* The ``PyLinter`` class will now be initialiazed with a ``TextReporter``
29
34
as its reporter if none is provided.
30
35
Original file line number Diff line number Diff line change @@ -26,6 +26,11 @@ Other Changes
26
26
27
27
Closes #4716
28
28
29
+ * Fix crash in ``unnecessary-dict-index-lookup `` checker if the output of
30
+ ``items() `` is assigned to a 1-tuple.
31
+
32
+ Closes #5504
33
+
29
34
* Fix false negative for ``consider-iterating-dictionary `` during membership checks encapsulated in iterables
30
35
or ``not in `` checks
31
36
Original file line number Diff line number Diff line change @@ -1882,6 +1882,8 @@ def _check_unnecessary_dict_index_lookup(
1882
1882
if isinstance (value , nodes .Name ):
1883
1883
if (
1884
1884
not isinstance (node .target , nodes .Tuple )
1885
+ # Ignore 1-tuples: for k, in d.items()
1886
+ or len (node .target .elts ) < 2
1885
1887
or value .name != node .target .elts [0 ].name
1886
1888
or iterating_object_name != subscript .value .as_string ()
1887
1889
):
Original file line number Diff line number Diff line change @@ -100,3 +100,10 @@ class Foo:
100
100
for key_two , val_two in val .items ():
101
101
del outer_dict [key ][key_two ] # [unnecessary-dict-index-lookup]
102
102
break
103
+
104
+ # Test partial unpacking of items
105
+ # https://github.com/PyCQA/pylint/issues/5504
106
+
107
+ d = {}
108
+ for key , in d .items ():
109
+ print (d [key ])
You can’t perform that action at this time.
0 commit comments