3 ms·
I generally agree with you. Building automatic validation on top of dataclasses seems like a far-superior solution moving forward, given the language's trajecto
by discardable_dan 5y ago
I generally agree with you. Building automatic validation on top of dataclasses seems like a far-superior solution moving forward, given the language's trajectory.
- guitarbill 5y agoIt's easy to say, but pydantic exists, and automatic validation on top of dataclasses does not/there's no well-known, well-tested library? (I'd also prefer something other than pydantic that doesn't coerce types by default, but alas...) And it's a huge use-case that should've been obvious. I get type annotations are not static typing, but hand-rolling validation doesn't feel like "batteries included". More generally, there are already tools using type annotations, and there'd likely be more if it was robust/easy. Python is generally good at enabling metaprogramming, but type annotations are a bit of a minefield. See even dataclass' own impl, e.g. [0]. And building on top of dataclasses is also tricky. I'm hopeful it can be resolved. Type annotations are a huge boon to the language, and it's already no small feat to have added them without breaking backwards compatibility. [0] https://github.com/python/cpython/blob/8a232c7b17a2e41ae14d8bb7937ddfea69301dce/Lib/dataclasses.py#L672 https://github.com/python/cpython/blob/8a232c7b17a2e41ae14d8...
- tomwojcik 5y agoDataclass child can't inherit from a parent that has a default value set. How is this not a dealbreaker for most? That's literally the only reason I keep using pydantic instead of dataclasses.
- Recursing 5y agoI agree it's a deal breaker, it's also the reason we have to use a custom solution :( If you can add the dependency I would recommend using attrs, it's so much better than the stdlib dataclasses :(
- mikkelam 5y agoPydantic does in fact support dataclasses as well, with a few caveats