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

Crash: AstroidError in refactoring_checker.py #8207

Closed
belm0 opened this issue Feb 7, 2023 · 6 comments · Fixed by #8209
Closed

Crash: AstroidError in refactoring_checker.py #8207

belm0 opened this issue Feb 7, 2023 · 6 comments · Fixed by #8209
Assignees
Labels
Crash 💥 A bug that makes pylint crash Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Milestone

Comments

@belm0
Copy link
Contributor

belm0 commented Feb 7, 2023

Bug description

proprietary code, I haven't tried to narrow it down

pylint crashed with AstroidError and with the following stacktrace:

Traceback (most recent call last):
  File "/.../python3.8/site-packages/pylint/lint/pylinter.py", line 798, in _lint_file
    check_astroid_module(module)
  File "/.../python3.8/site-packages/pylint/lint/pylinter.py", line 1067, in check_astroid_module
    retval = self._check_astroid_module(
  File "/.../python3.8/site-packages/pylint/lint/pylinter.py", line 1117, in _check_astroid_module
    walker.walk(node)
  File "/.../python3.8/site-packages/pylint/utils/ast_walker.py", line 94, in walk
    self.walk(child)
  File "/.../python3.8/site-packages/pylint/utils/ast_walker.py", line 94, in walk
    self.walk(child)
  File "/.../python3.8/site-packages/pylint/utils/ast_walker.py", line 94, in walk
    self.walk(child)
  [Previous line repeated 2 more times]
  File "/.../python3.8/site-packages/pylint/utils/ast_walker.py", line 91, in walk
    callback(astroid)
  File "/.../python3.8/site-packages/pylint/checkers/refactoring/refactoring_checker.py", line 1731, in visit_comprehension
    self._check_unnecessary_list_index_lookup(node)
  File "/.../python3.8/site-packages/pylint/checkers/refactoring/refactoring_checker.py", line 2208, in _check_unnecessary_list_index_lookup
    has_start_arg, confidence = self._enumerate_with_start(node)
  File "/.../python3.8/site-packages/pylint/checkers/refactoring/refactoring_checker.py", line 2326, in _enumerate_with_start
    start_val, confidence = self._get_start_value(start_arg)
  File "/.../python3.8/site-packages/pylint/checkers/refactoring/refactoring_checker.py", line 2346, in _get_start_value
    return node.operand.value, HIGH
AttributeError: 'Attribute' object has no attribute 'value'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/.../python3.8/site-packages/pylint/lint/pylinter.py", line 763, in _lint_files
    self._lint_file(fileitem, module, check_astroid_module)
  File "/.../python3.8/site-packages/pylint/lint/pylinter.py", line 800, in _lint_file
    raise astroid.AstroidError from e
astroid.exceptions.AstroidError

Configuration

No response

Command used

pylint

Pylint output

n/a

Expected behavior

n/a

Pylint version

pylint 2.16.1
astroid 2.14.1
Python 3.8.12 (default, Sep 23 2021, 08:42:37)
[Clang 12.0.0 (clang-1200.0.32.29)]

OS / Environment

No response

Additional dependencies

No response

@belm0 belm0 added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Feb 7, 2023
@orSolocate
Copy link
Contributor

@belm0 - do you know what line (in the code Pylint checked) caused the crash? or any way to reproduce your error?

@belm0
Copy link
Contributor Author

belm0 commented Feb 7, 2023

I was hoping it would be enough to imagine how the following might happen in the pylint code. If not, I'll try to whittle down the input.

  File "/.../python3.8/site-packages/pylint/checkers/refactoring/refactoring_checker.py", line 2346, in _get_start_value
    return node.operand.value, HIGH
AttributeError: 'Attribute' object has no attribute 'value'

@Pierre-Sassoulas Pierre-Sassoulas added Crash 💥 A bug that makes pylint crash Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Feb 7, 2023
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.16.2 milestone Feb 7, 2023
@Pierre-Sassoulas
Copy link
Member

Pierre-Sassoulas commented Feb 7, 2023

Could you provide the value of the start attribute that is not an int inside an enumerate ? 😄

@belm0
Copy link
Contributor Author

belm0 commented Feb 7, 2023

Could you provide the value of the start attribute that is not an int inside an enumerate ? 😄

Ah, that's exactly the code I've narrowed in on. Try this:

class Foo:
    def bar(self):
        return {
            (x, x): value
            for x, row in enumerate([(5, 10), (20, 30)])
            for y, value in enumerate(row, -self.unknown)}

In the original code, the attribute is defined, and it is an int type (no annotation, but the IDE infers it).

@Pierre-Sassoulas

@belm0
Copy link
Contributor Author

belm0 commented Feb 7, 2023

the problem seems to be the unary minus

class Foo:
    def __init__(self):
        self.offset = -10

    def bar(self):
        return {
            (x, x): value
            for x, row in enumerate([(5, 10), (20, 30)])
            for y, value in enumerate(row, -self.offset)}

@Pierre-Sassoulas
Copy link
Member

Thank you @belm0 amazing 👍

@Pierre-Sassoulas Pierre-Sassoulas added Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine labels Feb 7, 2023
github-actions bot pushed a commit that referenced this issue Feb 7, 2023
Pierre-Sassoulas added a commit that referenced this issue Feb 7, 2023
…8225)

Closes #8207

(cherry picked from commit 70f7e3a)

Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
@Pierre-Sassoulas Pierre-Sassoulas self-assigned this Feb 13, 2023
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 Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants