|
|
|
|
|
by nitred
1645 days ago
|
|
In my opinion Pydantic is Dataclass++ and NamedTuple+. I use it everywhere performance is not critical. It does type casting and provides an option for strict types. It lets you use custom types where you can define min and max size of a list or tuple etc. Every time I had a weird validation I needed to do, the Pydantic docs already had a built-in way to do it (E.g. conlist). It has excellent support for JSON and JSON schemas out of the box. Error messages are excellent! Tells you exactly what went wrong (most of the time) during validation. I do use Pydantic even when Dataclass and NamedTuples are sufficient, I know that's a bit cargo cultish but it lowers the mental overhead by just having to perfect one of way of doing things. |
|
That's exactly the point. The mental burden of remembering the quirks of (and having to choose between) namedtuples, typeddicts, dataclasses etc is very real.