Skip to content

Refactoring checker crashes when unary operator used with variable #9074

@Hnasar

Description

@Hnasar

Bug description

"""Regression test."""
def crash_on_unary_op_with_name():
    """Should not crash with -idx."""
    mylist = []
    idx = 5
    for _i, _val in enumerate(mylist, start=-idx):
        pass

Configuration

No response

Command used

pylint file.py

Pylint output

File "python3.10/site-packages/pylint/utils/ast_walker.py", line 91, in walk
        callback(astroid)
      File "python3.10/site-packages/pylint/checkers/refactoring/refactoring_checker.py", line 700, in visit_for
        self._check_unnecessary_list_index_lookup(node)
      File "python3.10/site-packages/pylint/checkers/refactoring/refactoring_checker.py", line 2227, in _check_unnecessary_list_index_lookup
        has_start_arg, confidence = self._enumerate_with_start(node)
      File "python3.10/site-packages/pylint/checkers/refactoring/refactoring_checker.py", line 2352, in _enumerate_with_start
        start_val, confidence = self._get_start_value(keyword.value)
      File "python3.10/site-packages/pylint/checkers/refactoring/refactoring_checker.py", line 2369, in _get_start_value
        return node.operand.value, HIGH
    AttributeError: 'Name' object has no attribute 'value'

Expected behavior

no crash

Pylint version

python3.10 -- latest version of pylint maintenance branch

OS / Environment

No response

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Crash 💥A bug that makes pylint crash

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions