Skip to content

frozen Sonde(s) #120

@d70-t

Description

@d70-t

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions