DEV Community

Discussion on: Reconciling Dataclasses And Properties In Python

Collapse
 
florimondmanca profile image
Florimond Manca

Hi! I do agree with you — it is probably less readable, and not very obvious. The reason being that there are many little details whose interplay allow this "trick" to even work.

So my answer would be: it depends on your priorities. Is it okay for you to sacrifice some readability over the advantages of dataclasses?

For example, it might not be okay because other people working on the project may not be familiar with dataclasses; they'd probably end up clueless about how it can even work.

Also, remember the Zen of Python: "there should be one — and preferably only one — way to do it." Consider alternatives; if they look more obvious, use them. Otherwise, go for @property. :-)