Skip to content

Slots and Generics handling broken since 2.5.3 #999

@svenpanne

Description

@svenpanne

Steps to reproduce

  1. Build a venv with pylint 2.7.4 and astroid 2.5.3, e.g. via pipenv install pylint==2.7.4 astroid==2.5.3.
  2. Run pylint on the following file via e.g. pipenv run pylint --disable=all --enable=assigning-non-slot broken.py:
from typing import Generic, TypeVar

T = TypeVar("T")


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


class Foo(Base[T]):
    __slots__ = ['_value']

    def __init__(self, value: T):
        # Triggers assigning-non-slot (Assigning to attribute '_value' not defined
        # in class slots), works when using Generic[T] directly as a base class.
        self._value = value

Current behavior

The steps above incorrectly trigger the assigning-non-slot check.

Expected behavior

No complaints from pylint. If you go back to astroid 2.5.2, the above works. If Foo directly inherits from Generic[T], the above works, too.

Bisecting shows that the commit cd0f896 introduced the regression. Therefore, every astroid >= 2.5.3 is buggy, as is every pylint >= 2.8.0.

python -c "from astroid import __pkginfo__; print(__pkginfo__.version)" output

As already mentioned above, the bug is present in every release containing the above commit, i.e. from 2.5.3 onwards.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions