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 ParentMissingError for comparison with Protocol.__name__ #8920

Open
AllexVeldman opened this issue Aug 3, 2023 · 0 comments
Open

Crash ParentMissingError for comparison with Protocol.__name__ #8920

AllexVeldman opened this issue Aug 3, 2023 · 0 comments
Labels
Astroid Related to astroid Crash 💥 A bug that makes pylint crash

Comments

@AllexVeldman
Copy link

AllexVeldman commented Aug 3, 2023

Bug description

Pylint crashes when comparing to __name__ on a Protocol.
Also applies to subclasses of the Protocol.

from typing import Protocol
# pylint: disable=missing-class-docstring,too-few-public-methods,pointless-statement

class Foo(Protocol):
    __name__: str

Foo.__name__ == "a"

Command used

pylint tmp.py

Pylint output

pylint crashed with a ``AstroidError`` and with the following stacktrace:

Exception on node <Compare l.10 at 0x103257ed0> in file '.../tmp.py'
Traceback (most recent call last):
  File "/.../pylint/checkers/utils.py", line 1390, in safe_infer
    value = next(infer_gen)
            ^^^^^^^^^^^^^^^
  File "/.../astroid/nodes/node_ng.py", line 171, in infer
    yield from self._infer(context=context, **kwargs)
  File "/.../astroid/decorators.py", line 143, in raise_if_nothing_inferred
    yield next(generator)
          ^^^^^^^^^^^^^^^
  File "/.../astroid/decorators.py", line 112, in wrapped
    for res in _func(node, context, **kwargs):
  File "/.../astroid/inference.py", line 372, in infer_attribute
    yield from owner.igetattr(self.attrname, context)
  File "/.../astroid/nodes/scoped_nodes/scoped_nodes.py", line 2650, in igetattr
    first_scope = first_attr.scope()
                  ^^^^^^^^^^^^^^^^^^
  File "/.../astroid/nodes/node_ng.py", line 362, in scope
    raise ParentMissingError(target=self)
astroid.exceptions.ParentMissingError: Parent not found on <Const.str l.None at 0x103a58dd0>.

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

Traceback (most recent call last):
  File "/.../pylint/utils/ast_walker.py", line 91, in walk
    callback(astroid)
  File "/.../pylint/checkers/base/comparison_checker.py", line 298, in visit_compare
    self._check_callable_comparison(node)
  File "/.../pylint/checkers/base/comparison_checker.py", line 276, in _check_callable_comparison
    inferred = utils.safe_infer(operand)
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.../pylint/checkers/utils.py", line 1394, in safe_infer
    raise AstroidError from e
astroid.exceptions.AstroidError
************* Module tmp
tmp.py:1:0: F0002: tmp.py: Fatal error while checking 'tmp.py'. Please open an issue in our bug tracker so we address this. There is a pre-filled template that you can use in '/.../pylint/pylint-crash-2023-08-03-14-41-00.txt'. (astroid-error)

Expected behavior

No crash

Pylint version

pylint 2.17.5
astroid 2.15.6
Python 3.11.4 (main, Jun 20 2023, 15:19:52) [Clang 14.0.3 (clang-1403.0.22.14.1)]

OS / Environment

OS: MacOS 13.4.1
Virtualenv: Created by poetry 1.5.1

@AllexVeldman AllexVeldman added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Aug 3, 2023
@Pierre-Sassoulas Pierre-Sassoulas added the Crash 💥 A bug that makes pylint crash label Aug 16, 2023
@Pierre-Sassoulas Pierre-Sassoulas added this to the 3.0.0 milestone Aug 16, 2023
@nickdrozd nickdrozd added Astroid Related to astroid and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Aug 28, 2023
@Pierre-Sassoulas Pierre-Sassoulas removed this from the 3.0.0 milestone Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Astroid Related to astroid Crash 💥 A bug that makes pylint crash
Projects
None yet
Development

No branches or pull requests

3 participants