File tree Expand file tree Collapse file tree 3 files changed +11
-2
lines changed
pylint/checkers/refactoring
tests/functional/r/regression_02 Expand file tree Collapse file tree 3 files changed +11
-2
lines changed Original file line number Diff line number Diff line change
1
+ Fixed a crash in ``unnecessary-dict-index-lookup`` when the index of an enumerated list
2
+ was deleted inside a for loop.
3
+
4
+ Closes #10726
Original file line number Diff line number Diff line change @@ -2355,10 +2355,10 @@ def _check_unnecessary_list_index_lookup(
2355
2355
or iterating_object_name != subscript .value .as_string ()
2356
2356
):
2357
2357
continue
2358
-
2359
2358
if (
2360
2359
isinstance (node , nodes .For )
2361
- and index .lookup (index .name )[1 ][- 1 ].lineno > node .lineno
2360
+ and (lookup_results := index .lookup (index .name )[1 ])
2361
+ and lookup_results [- 1 ].lineno > node .lineno
2362
2362
):
2363
2363
# Ignore this subscript if it has been redefined after
2364
2364
# the for loop.
Original file line number Diff line number Diff line change
1
+ """Test for deleted index."""
2
+ def test_deleted_index (letters : list [str ]) -> None :
3
+ for index , letter in enumerate (letters ):
4
+ del index
5
+ print (letters [index ])
You can’t perform that action at this time.
0 commit comments