Hacker News new | ask | show | jobs
by simonw 330 days ago
> I wish python had a clean way to define types without defining classes

dataclasses are pretty much that. They use the class mechanism but they're culturally accepted now as a clean way to build the equivalent of structs.

2 comments

^ Agreed.

And e.g. you can add dataclasses-json for JSON serializability: https://pypi.org/project/dataclasses-json/

Yes, dataclasses are great. I often use them as a pretty clear and adopted way to handle serialization and deserialization, configs, etc.