diff --git a/doc/whatsnew/fragments/7821.bugfix b/doc/whatsnew/fragments/7821.bugfix new file mode 100644 index 00000000000..30ed305e1e2 --- /dev/null +++ b/doc/whatsnew/fragments/7821.bugfix @@ -0,0 +1,3 @@ +Fixes bug that resulted in crash during ``unnecessary_list_index_lookup`` check. + +Closes #7821 diff --git a/pylint/checkers/refactoring/refactoring_checker.py b/pylint/checkers/refactoring/refactoring_checker.py index ec68099a6be..faf1637f844 100644 --- a/pylint/checkers/refactoring/refactoring_checker.py +++ b/pylint/checkers/refactoring/refactoring_checker.py @@ -2303,7 +2303,7 @@ def _enumerate_with_start( def _get_start_value(self, node: nodes.NodeNG) -> tuple[int | None, Confidence]: confidence = HIGH - if isinstance(node, (nodes.Name, nodes.Call)): + if isinstance(node, (nodes.Name, nodes.Call, nodes.Attribute)): inferred = utils.safe_infer(node) start_val = inferred.value if inferred else None confidence = INFERENCE diff --git a/tests/functional/u/unnecessary/unnecessary_list_index_lookup.py b/tests/functional/u/unnecessary/unnecessary_list_index_lookup.py index eb23938bcb1..71dcff0b838 100644 --- a/tests/functional/u/unnecessary/unnecessary_list_index_lookup.py +++ b/tests/functional/u/unnecessary/unnecessary_list_index_lookup.py @@ -138,3 +138,9 @@ def return_start(start): for idx, val in enumerate(): print(my_list[idx]) + +class Command: + def _get_extra_attrs(self, extra_columns): + self.extra_rows_start = 8 # pylint: disable=attribute-defined-outside-init + for index, column in enumerate(extra_columns, start=self.extra_rows_start): + pass