-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix crash in refactoring checker from unaryop with variable #9075
Conversation
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
8e14344
to
ab3e0f1
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #9075 +/- ##
==========================================
+ Coverage 95.57% 95.75% +0.18%
==========================================
Files 178 173 -5
Lines 18869 18664 -205
==========================================
- Hits 18034 17872 -162
+ Misses 835 792 -43
|
🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉 This comment was generated for commit ab3e0f1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch and fix !
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)
…9076) 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) Co-authored-by: Nazia Povey <Hnasar@users.noreply.github.com>
Are Hashem Nasarat and Nazia Povey the same person or should they be credited separately ? |
Hashem is fine, thanks! |
I'm trying to populate the alias file here: https://github.com/pylint-dev/pylint/blob/main/script/.contributors_aliases.json#L55 Would this work for you ? "Hnasar@users.noreply.github.com": {
"mails": ["Hnasar@users.noreply.github.com", "hashem@hudson-trading.com"],
"name": "Hashem Nasarat"
}, (Due to the |
Fixes:
Crash is reproducible if you have something like this:
As a workaround, remove the unary op before
for
loop (i.e. change the variable used).Closes #9074
Type of Changes