Skip to content

Crash AttributeError: 'TypeVar' object has no attribute 'assigned_stmts' #9098

@btjones0

Description

@btjones0

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

Metadata

Metadata

Labels

Crash 💥A bug that makes pylint crashNeeds astroid updateNeeds an astroid update (probably a release too) before being mergablepython 3.12

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions