-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
Enhancement ✨Improvement to a componentImprovement to a componentNeeds decision 🔒Needs a decision before implemention or rejectionNeeds a decision before implemention or rejection
Description
Current problem
The following is valid code but implicates some problems.
from dataclasses import dataclass
@dataclass
class MyClass:
__slots__ = ('foo', 'bar', )
foo: str
def __init__(self):
self.foo = 'one'
self.bar = 'two'
There are two slot variables (foo & bar) but only foo
is handled by the @dataclass
. For example str(MyClass())
will result in MyClass(foo="one")
. The variable bar
is missing in that output no matter that it exists.
Desired solution
PyLint should warn about that.
The list of variables in __slot__
do not fit to the list specificied for @dataclass
.
Python 3.10 or higher to offer @dataclass(slots=True)
to prevent situations like this. So this could be one possible solution PyLint could suggest. But there are also older Python versions still relevant.
Additional context
No response
Metadata
Metadata
Assignees
Labels
Enhancement ✨Improvement to a componentImprovement to a componentNeeds decision 🔒Needs a decision before implemention or rejectionNeeds a decision before implemention or rejection