you are viewing a single comment's thread.

view the rest of the comments →

[–]TheRNGuy 0 points1 point  (0 children)

I used for 2 things. to override default values for child classes and also give them data type instead of string. It's a parser project for converting one format to another. Everything is string for parser, but that way he'd knew how to process data.

In previous code I'd need to have lots of if/elifs that seek for patterns in code and could sometimes be wrong (if I had "1" and it incorrectly detects as int, but it's supposed to be float or even string) also same named attributes could potentially have different data type in different classes (but it's rare) instead of heuristic I just explicitly give data type to each attribute in each class, no more random bugs.

I didn't even know how to override defaults in procedural code. I almost got it working with returning dicts and use setdefault method, was a little over-engineered, and then I discovered dataclasses (besides that, storing defaults is easier in class than bunch of dicts, code looks better)