Skip to content

AttributeError: 'TypeVar' object has no attribute 'getattr' with __slots__ code #3258

Description

@correctmost

Steps to reproduce

The following code triggers an AttributeError in astroid:

class C[__slots__]:
    def __init__(self):
        self.a = 1

I found the bug during a local fuzzing run.

Current behavior

Traceback (most recent call last):
  File "pylint/pylint/utils/ast_walker.py", line 87, in walk
    callback(astroid)
    ~~~~~~~~^^^^^^^^^
  File "pylint/pylint/checkers/classes/class_checker.py", line 1880, in visit_assignattr
    self._check_in_slots(node)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "pylint/pylint/checkers/classes/class_checker.py", line 1954, in _check_in_slots
    slots = safe_slots(klass)
  File "pylint/pylint/checkers/utils.py", line 1521, in safe_slots
    return node.slots()  # type: ignore[no-any-return]
           ~~~~~~~~~~^^
  File "astroid/astroid/nodes/scoped_nodes/scoped_nodes.py", line 2822, in slots
    return self._all_slots
           ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.14/functools.py", line 1126, in __get__
    val = self.func(instance)
  File "astroid/astroid/nodes/scoped_nodes/scoped_nodes.py", line 2815, in _all_slots
    slots = list(grouped_slots(mro))
  File "astroid/astroid/nodes/scoped_nodes/scoped_nodes.py", line 2800, in grouped_slots
    cls_slots = cls._slots()
  File "astroid/astroid/nodes/scoped_nodes/scoped_nodes.py", line 2772, in _slots
    first = next(slots)
  File "astroid/astroid/nodes/scoped_nodes/scoped_nodes.py", line 2724, in _islots
    slots.getattr(meth)
    ^^^^^^^^^^^^^
AttributeError: 'TypeVar' object has no attribute 'getattr'

Expected behavior

No crash

Version info

cec5b897
pylint-dev/pylint@5ba4f69e7
Python 3.14.7

The crash is not reproducible with Pylint 4.0.7

Bisection data

Introduced with commit 4ea0c82 (#3058)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions