News for hackers. Stuff that matters.
Re:You might not need a Python class by simonw on Thursday July 24, 2025 @04:21PM (#44675567)
> 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.

Re:You might not need a Python class by paulddraper on Thursday July 24, 2025 @04:30PM (#44675715)
^ Agreed.

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

Re:You might not need a Python class by isjustintime on Thursday July 24, 2025 @09:15PM (#44678384)
Yes, dataclasses are great. I often use them as a pretty clear and adopted way to handle serialization and deserialization, configs, etc.