Skip to content
New issue

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

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

Already on GitHub? # to your account

Crash with slots+Generic #4578

Closed
markokr opened this issue Jun 15, 2021 · 3 comments
Closed

Crash with slots+Generic #4578

markokr opened this issue Jun 15, 2021 · 3 comments
Labels
Blocker 🙅 Blocks the next release Crash 💥 A bug that makes pylint crash
Milestone

Comments

@markokr
Copy link

markokr commented Jun 15, 2021

Steps to reproduce

Given a file a.py:

from typing import Generic, TypeVar

T = TypeVar("T")

class Base(Generic[T]):
    __slots__ = ()

class Sub(Base[T]):
    __slots__ = ("_ref",)
    _ref: Base[T]
    def __init__(self, ref):
        self._ref = ref     # astroid.exceptions.AttributeInferenceError: '_ref' not found

Current behavior

Result of pylint a.py:

Exception on node <AssignAttr._ref l.13 at 0x7efd712bc9d0> in file 'a.py'
Traceback (most recent call last):
   ...
astroid.exceptions.AttributeInferenceError: '_ref' not found on <ClassDef.Sub l.9 at 0x7efd7130ddc0>.

Expected behavior

No errors.

pylint --version output

Result of pylint --version output:

$ pylint --version
pylint 2.8.3
astroid 2.5.6
Python 3.8.5 (default, May 27 2021, 13:30:53) 
[GCC 9.3.0]
@Pierre-Sassoulas Pierre-Sassoulas added Crash 💥 A bug that makes pylint crash Blocker 🙅 Blocks the next release labels Jun 15, 2021
@Pierre-Sassoulas
Copy link
Member

Hello, thank you for opening the issue. could you share a little more of the stacktrace please ? Right now this won't be found if someone search for this problem on a search engine :)

@markokr
Copy link
Author

markokr commented Jun 15, 2021

If you think it helps. Here is full stacktrace:

Exception on node <AssignAttr._ref l.13 at 0x7f7bb89eda00> in file 'a.py'
Traceback (most recent call last):
  File "/home/marko/.local/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
  File "/home/marko/.local/lib/python3.8/site-packages/pylint/__init__.py", line 24, in run_pylint
    PylintRun(sys.argv[1:])
  File "/home/marko/.local/lib/python3.8/site-packages/pylint/lint/run.py", line 381, in __init__
    linter.check(args)
  File "/home/marko/.local/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 873, in check
    self._check_files(
  File "/home/marko/.local/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 907, in _check_files
    self._check_file(get_ast, check_astroid_module, name, filepath, modname)
  File "/home/marko/.local/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 933, in _check_file
    check_astroid_module(ast_node)
  File "/home/marko/.local/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1067, in check_astroid_module
    retval = self._check_astroid_module(
  File "/home/marko/.local/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1112, in _check_astroid_module
    walker.walk(ast_node)
  File "/home/marko/.local/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 77, in walk
    self.walk(child)
  File "/home/marko/.local/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 77, in walk
    self.walk(child)
  File "/home/marko/.local/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 77, in walk
    self.walk(child)
  [Previous line repeated 1 more time]
  File "/home/marko/.local/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 74, in walk
    callback(astroid)
  File "/home/marko/.local/lib/python3.8/site-packages/pylint/checkers/classes.py", line 1271, in visit_assignattr
    self._check_in_slots(node)
  File "/home/marko/.local/lib/python3.8/site-packages/pylint/checkers/classes.py", line 1306, in _check_in_slots
    if node.attrname in klass.locals and _has_data_descriptor(
  File "/home/marko/.local/lib/python3.8/site-packages/pylint/checkers/classes.py", line 345, in _has_data_descriptor
    attributes = cls.getattr(attr)
  File "/home/marko/.local/lib/python3.8/site-packages/astroid/scoped_nodes.py", line 2499, in getattr
    raise exceptions.AttributeInferenceError(
astroid.exceptions.AttributeInferenceError: '_ref' not found on <ClassDef.Sub l.9 at 0x7f7bb89d2d90>.

@cdce8p
Copy link
Member

cdce8p commented Jun 15, 2021

I can't reproduce it with the master branch anymore. Seems like #4522 fix already fixed it. That will be included with the v2.9.0 release of pylint. I'm going to close the issue. If it remains a problem after the release, feel free to come back here.

@cdce8p cdce8p closed this as completed Jun 15, 2021
@cdce8p cdce8p added this to the 2.9.0 milestone Jun 15, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Blocker 🙅 Blocks the next release Crash 💥 A bug that makes pylint crash
Projects
None yet
Development

No branches or pull requests

3 participants