3 ms·
> But for the many other purposes of classes that need custom init, write your own `__init__` method then, as you would anyway. Dataclass' default init is way
by zzzeek 4y ago
> But for the many other purposes of classes that need custom init,
write your own `__init__` method then, as you would anyway. Dataclass' default init is way better than that of `object`.
> advanced field defaults
same
> no equality
set eq=False, all dataclass methods are optional
> custom repr/str
write __repr__ and __str__ methods, same as init, dataclass' default is much nicer than that of `object`
> advanced inheritance
What's the issue with inheritance? what's "advanced" inheritance, you mean mixins?
> etc dataclasses give you nothing but a bunch of magic to turn off or work around.
Python `object` has all kinds of default behaviors too, which are just worse. default behaviors aren't "magic". dataclasses currently manufactures its methods at runtime, so that's maybe "magic", but all of that could be built into Python, then it would just be, "default behavior".
- PartiallyTyped 4y agoRe __init__ and advanced defaults, these may be achieved/set using __post_init__.
- athorax 4y agoFor awhile inheritance with dataclasses was fairly broken. They added kw_only in 3.10 which definitely helped. Even outside of dataclasses, python's MRO can be a footgun with multiple inheritance This video has some good explanations of inheritance behavior in python https://www.youtube.com/watch?v=X1PQ7zzltz4 https://www.youtube.com/watch?v=X1PQ7zzltz4