3 ms·
Forget about DataClasses, TypedDict etc. Can't you achieve the same in python with a class and a dict? Is there a difference, other than perhaps being overloade
by mathisonturing 4y ago
Forget about DataClasses, TypedDict etc.
Can't you achieve the same in python with a class and a dict? Is there a difference, other than perhaps being overloaded with options?
- xigoi 4y agoA dataclass will get things like __repr__ for free.
- PartiallyTyped 4y agoEq, hash, and init is also "free".
- throwaway894345 4y agoThere’s also implementation differences. Accessing attributes and methods on a regular class may be slower because (IIRC) it has to do a lookup on each instance’s dict, whereas I believe dataclass implementation is more optimized (I’ve clearly forgotten the details).