3 ms·
Why Python interpreter can't figure it out like "oh this class only stores data, so it must be a data class". No need for decorators etc. What would be the con
by varispeed 4y ago
Why Python interpreter can't figure it out like "oh this class only stores data, so it must be a data class". No need for decorators etc.
What would be the consequences of non-data class that only contains data to treat is as a data class? Likely none.
- dec0dedab0de 4y agoData classes are just regular classes but with some extra syntactic sugar(magic) to automate some common stuff.
- kortex 4y agoGood luck introspecting a given python object and ascertaining "this class only stores data". It's literally impossible given the dynamicism of python. The consequences are exposing state that you don't necessarily want to expose, missed opportunities for optimization (lose fine-grained memory/performance tradeoff ability), imply something is serializable when it isn't, collisions with metaclasses/inheritance weirdness.