dataclasses_slots
error
Dataclass slots violations
Reports errors when: - self.attr = value assigns to an attribute not in __slots__ inside a class with @dataclass(slots=True) or a manual __slots__ definition. - ClassName.__slots__ or ClassName().__slots__ is accessed on a dataclass that does not define __slots__ (neither via slots=True nor a manual __slots__ assignment).
@dataclass(slots=True)
class DC:
x: int
def __init__(self):
self.y = 3 # E: "y" is not in __slots__
@dataclass
class DC2:
a: int
DC2.__slots__ # E: __slots__ not defined
How to handle it
Every rule is on by default — strict is the default, not a cage. You can dial
dataclasses_slots down per-file or per-path from your editor or
pyproject.toml, or fix the code
so it type-checks. See the Type System rules and
the complete diagnostic reference.
Canonical URL: https://www.basilisk-python.dev/errors/dataclasses_slots