Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash in refactoring checker from unaryop with variable #9075

Commits on Sep 26, 2023

  1. Fix crash in refactoring checker from unaryop with variable

    Fixes:
    ```
      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'
    ```
    
    Crash is reproducible if you have something like this:
    
    ```python
    x=5
    for _ in enumerate(range, start=-x):
        ...
    ```
    
    As a workaround, remove the unary op before `for` loop (i.e. change the
    variable used).
    
    Closes pylint-dev#9074
    Hnasar committed Sep 26, 2023
    Configuration menu
    Copy the full SHA
    ab3e0f1 View commit details
    Browse the repository at this point in the history