Skip to content

Commit c191af8

Browse files
committed
handle Attribute
1 parent 73dfd82 commit c191af8

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

doc/whatsnew/fragments/7821.bugfix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fixes bug that resulted in crash during ``unnecessary_list_index_lookup`` check.
2+
3+
Closes #7821

pylint/checkers/refactoring/refactoring_checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2303,7 +2303,7 @@ def _enumerate_with_start(
23032303
def _get_start_value(self, node: nodes.NodeNG) -> tuple[int | None, Confidence]:
23042304
confidence = HIGH
23052305

2306-
if isinstance(node, (nodes.Name, nodes.Call)):
2306+
if isinstance(node, (nodes.Name, nodes.Call, nodes.Attribute)):
23072307
inferred = utils.safe_infer(node)
23082308
start_val = inferred.value if inferred else None
23092309
confidence = INFERENCE

tests/functional/u/unnecessary/unnecessary_list_index_lookup.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,9 @@ def return_start(start):
138138

139139
for idx, val in enumerate():
140140
print(my_list[idx])
141+
142+
class Command:
143+
def _get_extra_attrs(self, extra_columns):
144+
self.extra_rows_start = 8 # pylint: disable=attribute-defined-outside-init
145+
for index, column in enumerate(extra_columns, start=self.extra_rows_start):
146+
pass

0 commit comments

Comments
 (0)