Skip to content

Commit

Permalink
Revert "Fix crash when using enumerate with start and a class…
Browse files Browse the repository at this point in the history
… attribute (#7824)" (#7855)

This reverts commit 86b8c64.
  • Loading branch information
Pierre-Sassoulas committed Nov 29, 2022
1 parent ff73282 commit 43109b6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 29 deletions.
3 changes: 0 additions & 3 deletions doc/whatsnew/fragments/7821.bugfix

This file was deleted.

16 changes: 9 additions & 7 deletions pylint/checkers/refactoring/refactoring_checker.py
Expand Up @@ -2248,13 +2248,15 @@ def _enumerate_with_start(
return False, confidence

def _get_start_value(self, node: nodes.NodeNG) -> tuple[int | None, Confidence]:
if isinstance(node, (nodes.Name, nodes.Call, nodes.Attribute)):
confidence = HIGH

if isinstance(node, (nodes.Name, nodes.Call)):
inferred = utils.safe_infer(node)
start_val = inferred.value if inferred else None
return start_val, INFERENCE
if isinstance(node, nodes.UnaryOp):
return node.operand.value, HIGH
if isinstance(node, nodes.Const):
return node.value, HIGH
confidence = INFERENCE
elif isinstance(node, nodes.UnaryOp):
start_val = node.operand.value
else:
start_val = node.value

return None, HIGH
return start_val, confidence
19 changes: 0 additions & 19 deletions tests/functional/u/unnecessary/unnecessary_list_index_lookup.py
Expand Up @@ -130,22 +130,3 @@ def return_start(start):

for i, k in enumerate(series, return_start(20)):
print(series[idx])

for idx, val in enumerate(iterable=series, start=0):
print(series[idx]) # [unnecessary-list-index-lookup]

result = [my_list[idx] for idx, val in enumerate(iterable=my_list)] # [unnecessary-list-index-lookup]

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

Y_START = 2
nums = list(range(20))
for y, x in enumerate(nums, start=Y_START + 1):
pass

0 comments on commit 43109b6

Please sign in to comment.