Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Is there a reason to use data classes over pedantic base models anymore?


I guess some prefer to stick with the stdlib instead of third party libs.

Also, dataclasses feels more straightforward and less "magic" to me (in the sense that it is more or less "just" a way to avoid boilerplate for class definition, while pydantic does way more "magic" stuff like de-/serialization and validation, and adding numerous methods and attributes to the classes).


I’ve never really gotten along with Pydantic. Something about it just doesn’t feel ergonomic.

If I need something more than dataclasses, I’ll normally go for attrs/cattrs. Dataclasses were originally based on attrs, so it’s not much of a leap.


I never understood why basemodel even exists.

When I started to implement typedload, when types were just introduced, I supported NamedTuple, and then as more things were added, also attrs, dataclasses, typed dict…

What would be the point to require migrating the whole codebase to use something different to use your library?

On the other hand, if you wrote your code from scratch to use basemodel you're pretty much stuck with pydantic.


Speed and size, mainly. If you don't need the data validation there's no reason to use pydantic, it's a huge dependency


did you mean: "pydantic base models" ?


Yeah haha I got autocorrected


speed? Not pulling in a huge dependency?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: