Skip to content

SLOT002 gives a false positive because does take into account multiple inheritance #11887

@alessio-locatelli

Description

@alessio-locatelli

Search I have tried

SLOT002

There are no duplicate issues.

Problem

Ruff says to me:

SLOT002 Subclasses of `collections.namedtuple()` should define `__slots__`

But I inherit from namedtuple and Enum at the same time.

Reproducible example

from collections import namedtuple
from enum import Enum


class Foobar(namedtuple("conventional_sign", "name description"), Enum):
    __slots__ = ()
    FOO = 1, "Hello, World!"
    BAR = 2, "Some text here"

    @classmethod
    def item_description(cls, conventional_sign: int) -> str:
        for value in cls.__members__.values():
            if conventional_sign == value[0]:
                return value[1]
        raise ValueError(f"{conventional_sign} not in {cls.__members__.values()}")

Correct (expected) behavior

Look on all parent classes before recommending to add __slots__.

For example, Enum has no __slots__ (python/cpython#90290).

Versions

  • Python 3.12.4
  • ruff 0.4.9

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions