|
|
|
|
|
by itamarst
386 days ago
|
|
You can't add extra attributes that weren't part of the original dataclass definition: >>> from dataclasses import dataclass
>>> @dataclass
... class C: pass
...
>>> C().x = 1
>>> @dataclass(slots=True)
... class D: pass
...
>>> D().x = 1
Traceback (most recent call last):
File "<python-input-4>", line 1, in <module>
D().x = 1
^^^^^
AttributeError: 'D' object has no attribute 'x' and no __dict__ for setting new attributes
Most of the time this is not a thing you actually need to do. |
|
If you're using dataclasses it's less of an issue because dataclasses.asdict.