Or data bearing enums, which bring some of the best of all of those worlds, with (value declaration, not usage) exhaustiveness enforced at compile time:
They do different things but in the wild are used in the same way. Data classes are not immutable so it would not be ideal for what I used named tuples for.
Data classes can be made immutable using ‘frozen=True’. It sucks that it’s not default though.
Can you give an example of how you use enums and named tuples in the same way? That just doesn’t seem to make a lot of sense to me, but maybe I’m missing something.
https://github.com/klaviyo/matrix_enum
My colleague and I started making use of that pattern last year (before open sourcing the package) and found it very useful.