qudi.util.descriptors.ReadOnlyAttribute
- class qudi.util.descriptors.ReadOnlyAttribute(default: ~typing.Any | None = <object object>)[source]
Bases:
qudi.util.descriptors.ReadOnlyMixin,qudi.util.descriptors.DefaultAttributeExtension of DefaultAttribute to be read-only. A non-default value can be set by calling “set_value(instance, value)” on the descriptor instance.
Example usage:
- class Test:
variable_a = ReadOnlyAttribute(42) variable_b = ReadOnlyAttribute() def __init__(self):
self.__class__.variable_b.set_value(self, self.variable_a - 42) assert self.variable_a == 42 assert self.variable_b == 0 # The following would raise an AttributeError # self.variable_b = 0
- __init__(default: ~typing.Any | None = <object object>)
Methods
__init__([default])set_value(instance, value)- set_value(instance: object, value: Any) None