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=False and use normal attribute assignment (this will effectively keep the code the same, but is more obvious to the reader)
- actually use
Sonde as a frozen object. The current workflow in many cases works with functions accepting a Sonde and returning a Sonde. Instead of return self, the better option would be to return dataclasses.replace(self, some_attribute=new_value, ...), which would create a new frozen Sonde object with some attributes replaced. The latter option would also require to declare all attributes upfront (as usual with dataclasses).
With 2c102ec, the
Sondeclass has been converted to a frozen dataclass. The reasoning behind this change is probably valid and I agree, thatfrozencould be a good design choice in this place. But then, immediately, there's a hot hack to escape the freezer usingobject.__setattr__, which essentially circumvents everything adataclassprovides. 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, theSondeis all but frozen, so it's a lie. We should get rid of this lie. Possible options are:frozen=Falseand use normal attribute assignment (this will effectively keep the code the same, but is more obvious to the reader)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).