Skip to content

PLE0237 false positive for slots literal concatenation  #11333

@airallergy

Description

@airallergy

I have a class, whose slots are formed by concatenating other literal tuples via RUF005 style. Below B is reported to violate PLE0237, which is a false positive, I also tried a few variants of B:

  • C: If B is a subclass of any other class, PLE0237 seems to work fine
  • D: If B slots has no other literal items, PLE0237 seems to work fine
  • E: If B slots uses tuple concatenation, which violates RUF005, but PLE0237 seems to work fine
class A:
    pass


class B:
    names = ("x",)
    __slots__ = (*names, "a")

    def __init__(self) -> None:
        self.x = 1  # PLE0237: Attribute `x` is not defined in class's `__slots__`


class C(A):
    names = ("x",)
    __slots__ = (*names, "a")

    def __init__(self) -> None:
        self.x = 1


class D:
    names = ("x",)
    __slots__ = (*names,)

    def __init__(self) -> None:
        self.x = 1


class E:
    names = ("x",)
    __slots__ = names + ("a",)  # RUF005: Consider `(*names, "a")` instead of concatenation

    def __init__(self) -> None:
        self.x = 1

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