3 ms·
> This seems to be missing my biggest gripe: adding new attributes to classes outside of `__init__()` or `__slots__`. You don't strictly need to use dataclasse
by hermitdev 5y ago
> This seems to be missing my biggest gripe: adding new attributes to classes outside of `__init__()` or `__slots__`.
You don't strictly need to use dataclasses to accomplish this. Yes, you get stronger guarantees with dataclasses (such as runtime checks, and these come with a runtime cost), but you can declare your members the same and use a properly configured linter that will tell you if you're assigning members from places you shouldn't.
Personally, I tend use dataclasses more for plain old data types. As soon as one starts needing/wanting to control __init__, I find the utility of dataclasses drops precipitously. But, I do still annotate my (public) members with proper types, trying to avoid `Any` as much as possible.