Back to Intellij Community

PyDunderSlotsInspection

python/python-psi-impl/resources/inspectionDescriptions/PyDunderSlotsInspection.html

2025.3-rc-2560 B
Original Source

Reports invalid usages of a class with __slots__ definitions.

Example when accessing undefined attributes:

class Foo:
    __slots__ = ['foo', 'bar']

    def __init__ (self):
        self.x = 3 # error: 'x' is not defined in __slots__

Example of conflicting attributes:

class A:
    __slots__ = ("x",)
    x = 42 # error: conflict with "x" listed in __slots__

Example slots=True:

from dataclasses import dataclass

@dataclass(slots=True) # error: __slots__ is also defined in Foo
class Foo:
    __slots__ = ['a']