Skip to content

false positive "assigning-non-slot" error for inherited descriptor when slots are used #6001

Closed
@jab

Description

@jab

Bug description

Minimized reproducer:

"""Repro false positive bug in pylint."""


# pylint: disable=too-few-public-methods


class MyDescriptor:
    """Basic descriptor."""

    def __get__(self, instance, owner):
        return 42

    def __set__(self, instance, value):
        pass


class Base:
    """Base class with slots."""

    __slots__ = ()

    attr2 = MyDescriptor()


class Repro(Base):
    """Reproduce false positive error using this class."""

    __slots__ = ()


repro = Repro()
repro.attr2 = 'false positive "assigning-non-slot" error'  # false positive error here

A real-world (non-minimized) example where pylint produces this false positive error can be found on this line: https://github.com/jab/bidict/blob/caf703e959ed4471bc391a7794411864c1d6ab9d/bidict/_orderedbase.py#L101

Configuration

No response

Command used

pylint repro.py

Pylint output

************* Module repro
repro.py:32:0: E0237: Assigning to attribute 'attr2' not defined in class slots (assigning-non-slot)

Expected behavior

No error should be flagged here.

Pylint version

pylint 2.13.2
astroid 2.11.2
Python 3.10.2 (main, Feb  2 2022, 07:36:01) [Clang 12.0.0 (clang-1200.0.32.29)]

OS / Environment

No response

Additional dependencies

No response

Metadata

Metadata

Assignees

Labels

Bug 🪲False Positive 🦟A message is emitted but nothing is wrong with the code

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions