-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Labels
Description
Currently, PLE0237 will report "Attribute other is not defined in class's __slots__" on a class like this:
class A:
__slots__ = ("pub",)
def __init__(self) -> None:
self.other = "hi"Which is correct. But it also reports the same error on the following correct class:
class B:
__slots__ = ("pub", "__dict__")
def __init__(self) -> None:
self.other = "hi"This is incorrect; since the class has a __dict__ in it's __slots__, it has a dict to put other in. This is described in https://docs.python.org/3/reference/datamodel.html#slots (both __dict__ and __weakref__ can be declared in __slots__), and is an important technique for wrapper classes, where the wrapped object is declared in slots, so that the __dict__ has everything except the wrapped object.
Incorrect check result seen in scikit-hep/boost-histogram#914.
- Command
ruff check --select=ALL --isolated tmp.py - Ruff version: ruff 0.3.1
Reactions are currently unavailable