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

[Backport maintenance/2.17.x] Fix crash in refactoring checker from unaryop with variable #9076

Merged

Conversation

github-actions[bot]
Copy link
Contributor

Backport aa29201 from #9075.

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 #9074

Co-authored-by: Hashem Nasarat <hashem@hudson-trading.com>
(cherry picked from commit aa29201)
@Pierre-Sassoulas Pierre-Sassoulas added the Crash 💥 A bug that makes pylint crash label Sep 27, 2023
@codecov
Copy link

codecov bot commented Sep 27, 2023

Codecov Report

Merging #9076 (7bd258b) into maintenance/2.17.x (b8a7cc5) will not change coverage.
The diff coverage is n/a.

Additional details and impacted files

Impacted file tree graph

@@                 Coverage Diff                 @@
##           maintenance/2.17.x    #9076   +/-   ##
===================================================
  Coverage               95.57%   95.57%           
===================================================
  Files                     178      178           
  Lines                   18869    18869           
===================================================
  Hits                    18034    18034           
  Misses                    835      835           
Files Coverage Δ
pylint/checkers/refactoring/refactoring_checker.py 98.34% <ø> (ø)

@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.17.7 milestone Sep 27, 2023
@Pierre-Sassoulas Pierre-Sassoulas merged commit aed51a6 into maintenance/2.17.x Sep 27, 2023
26 checks passed
@Pierre-Sassoulas Pierre-Sassoulas deleted the backport-9075-to-maintenance/2.17.x branch September 27, 2023 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Crash 💥 A bug that makes pylint crash
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants