Hacker News new | ask | show | jobs
by mathisonturing 1454 days 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?
2 comments

A dataclass will get things like __repr__ for free.
Eq, hash, and init is also "free".
There’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).