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 AttributeError: 'TypeVar' object has no attribute 'assigned_stmts' #9098

Closed
btjones0 opened this issue Oct 3, 2023 · 5 comments · Fixed by pylint-dev/astroid#2320
Closed
Assignees
Labels
Crash 💥 A bug that makes pylint crash Needs astroid update Needs an astroid update (probably a release too) before being mergable python 3.12
Milestone

Comments

@btjones0
Copy link

btjones0 commented Oct 3, 2023

Bug description

Trying to use the new PEP 695 syntax for generic classes.

class A[T]: ...

Configuration

No response

Command used

pylint a.py

Pylint output

Traceback (most recent call last):
  File "/Users/btjones/.local/pipx/venvs/pylint/lib/python3.12/site-packages/pylint/checkers/utils.py", line 1359, in safe_infer
    value = next(infer_gen)
            ^^^^^^^^^^^^^^^
  File "/Users/btjones/.local/pipx/venvs/pylint/lib/python3.12/site-packages/astroid/nodes/node_ng.py", line 169, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
  File "/Users/btjones/.local/pipx/venvs/pylint/lib/python3.12/site-packages/astroid/decorators.py", line 90, in inner
    yield next(generator)
          ^^^^^^^^^^^^^^^
  File "/Users/btjones/.local/pipx/venvs/pylint/lib/python3.12/site-packages/astroid/decorators.py", line 49, in wrapped
    for res in _func(node, context, **kwargs):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/btjones/.local/pipx/venvs/pylint/lib/python3.12/site-packages/astroid/nodes/node_classes.py", line 457, in _infer
    stmts = list(self.assigned_stmts(context=context))
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/btjones/.local/pipx/venvs/pylint/lib/python3.12/site-packages/astroid/protocols.py", line 345, in assend_assigned_stmts
    return self.parent.assigned_stmts(node=self, context=context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'TypeVar' object has no attribute 'assigned_stmts'

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

Traceback (most recent call last):
  File "/Users/btjones/.local/pipx/venvs/pylint/lib/python3.12/site-packages/pylint/lint/pylinter.py", line 788, in _lint_file
    check_astroid_module(module)
  File "/Users/btjones/.local/pipx/venvs/pylint/lib/python3.12/site-packages/pylint/lint/pylinter.py", line 1017, in check_astroid_module
    retval = self._check_astroid_module(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/btjones/.local/pipx/venvs/pylint/lib/python3.12/site-packages/pylint/lint/pylinter.py", line 1069, in _check_astroid_module
    walker.walk(node)
  File "/Users/btjones/.local/pipx/venvs/pylint/lib/python3.12/site-packages/pylint/utils/ast_walker.py", line 94, in walk
    self.walk(child)
  File "/Users/btjones/.local/pipx/venvs/pylint/lib/python3.12/site-packages/pylint/utils/ast_walker.py", line 91, in walk
    callback(astroid)
  File "/Users/btjones/.local/pipx/venvs/pylint/lib/python3.12/site-packages/pylint/checkers/classes/class_checker.py", line 878, in visit_classdef
    self._check_bases_classes(node)
  File "/Users/btjones/.local/pipx/venvs/pylint/lib/python3.12/site-packages/pylint/checkers/classes/class_checker.py", line 2128, in _check_bases_classes
    unimplemented_abstract_methods(node, is_abstract).items(),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/btjones/.local/pipx/venvs/pylint/lib/python3.12/site-packages/pylint/checkers/utils.py", line 959, in unimplemented_abstract_methods
    inferred = safe_infer(obj)
               ^^^^^^^^^^^^^^^
  File "/Users/btjones/.local/pipx/venvs/pylint/lib/python3.12/site-packages/pylint/checkers/utils.py", line 1363, in safe_infer
    raise AstroidError from e
astroid.exceptions.AstroidError

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

Traceback (most recent call last):
  File "/Users/btjones/.local/pipx/venvs/pylint/lib/python3.12/site-packages/pylint/lint/pylinter.py", line 752, in _lint_files
    self._lint_file(fileitem, module, check_astroid_module)
  File "/Users/btjones/.local/pipx/venvs/pylint/lib/python3.12/site-packages/pylint/lint/pylinter.py", line 790, in _lint_file
    raise astroid.AstroidError from e
astroid.exceptions.AstroidError

Expected behavior

No crash.

Pylint version

pylint 3.0.0
astroid 3.0.0
Python 3.12.0 (main, Oct  2 2023, 15:13:44) [Clang 15.0.0 (clang-1500.0.40.1)]

OS / Environment

darwin (Darwin)

Additional dependencies

No response

@btjones0 btjones0 added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Oct 3, 2023
@Pierre-Sassoulas Pierre-Sassoulas added Crash 💥 A bug that makes pylint crash python 3.12 Needs astroid update Needs an astroid update (probably a release too) before being mergable and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Oct 3, 2023
@mbyrnepr2
Copy link
Member

@btjones0 could you please provide a fully working reproducible example? The provided one gives a syntax error:

    class A[T]: ...
           ^
SyntaxError: expected ':'

@btjones0
Copy link
Author

btjones0 commented Oct 3, 2023

This is a fully reproducible example in python 3.12. I agree that it would be a syntax error in python 3.11 prior to PEP 695.

@mbyrnepr2
Copy link
Member

Ah thanks :). I was using an older build of 3.12. Time for coffee!

@jacobtylerwalls
Copy link
Member

Thanks. Missed this in pylint-dev/astroid#2252.

@jacobtylerwalls jacobtylerwalls self-assigned this Oct 3, 2023
@jacobtylerwalls
Copy link
Member

jacobtylerwalls commented Oct 3, 2023

(deleted the diff, needs more thought)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Crash 💥 A bug that makes pylint crash Needs astroid update Needs an astroid update (probably a release too) before being mergable python 3.12
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants