With https://github.com/Geet-George/halodrops/commit/2c102ec8c53c52eaa3391dd45643d372176d9733, 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).
I agree. I had forgotten that I had it as a frozen dataclass. Of both options you suggest, I would prefer the latter (although the former is a quick change!). I'll see if I can get to this soon enough :/
With https://github.com/Geet-George/halodrops/commit/2c102ec8c53c52eaa3391dd45643d372176d9733, the
Sonde
class has been converted to a frozen dataclass. The reasoning behind this change is probably valid and I agree, thatfrozen
could 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 adataclass
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, theSonde
is all but frozen, so it's a lie. We should get rid of this lie. Possible options are:frozen=False
and use normal attribute assignment (this will effectively keep the code the same, but is more obvious to the reader)Sonde
as 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 frozenSonde
object with some attributes replaced. The latter option would also require to declare all attributes upfront (as usual with dataclasses).