This is a drive-by change after spending some quality time with the mount code. The `id` field of `Mount` is calculated only once and only when creating a `Mount`. This seems slightly dangerous as any change to an attribute after creation will not update the id. This means two options: 1. dynamically update the `id` on changes 2. forbid changes after the `id` is calculcated I went with (2) but happy to discuss of course but it seems more the spirit of the class. It also does the same change for "devices.Device"
15 lines
406 B
Python
15 lines
406 B
Python
"""
|
|
Mixin helper classes
|
|
"""
|
|
|
|
|
|
class MixinImmutableID:
|
|
"""
|
|
Mixin to ensure that "self.id" attributes are immutable after id is set
|
|
"""
|
|
|
|
def __setattr__(self, name, val):
|
|
if hasattr(self, "id"):
|
|
class_name = self.__class__.__name__
|
|
raise ValueError(f"cannot set '{name}': {class_name} cannot be changed after creation")
|
|
super().__setattr__(name, val)
|