-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
With 2c102ec, the Sonde class has been converted to a frozen dataclass. The reasoning behind this change is probably valid and I agree, that frozen could be a good design choice in this place. But then, immediately, there's a hot hack to escape the freezer using object.__setattr__, which essentially circumvents everything a dataclass provides. It's also hard to read and a bit unexpected to the casual Python reader.
In the meantime, this hack has spread quite a bit (as of now, I count 36 occurrences of object.__setattr__), so in fact, the Sonde is all but frozen, so it's a lie. We should get rid of this lie. Possible options are:
- set
frozen=Falseand use normal attribute assignment (this will effectively keep the code the same, but is more obvious to the reader) - actually use
Sondeas a frozen object. The current workflow in many cases works with functions accepting a Sonde and returning a Sonde. Instead ofreturn self, the better option would be toreturn dataclasses.replace(self, some_attribute=new_value, ...), which would create a new frozenSondeobject with some attributes replaced. The latter option would also require to declare all attributes upfront (as usual with dataclasses).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels