qudi.util.descriptors.TypedAttribute
- class qudi.util.descriptors.TypedAttribute(valid_types: ~typing.Iterable[~typing.Type] | None = None, default: ~typing.Any | None = <object object>)[source]
Bases:
qudi.util.descriptors.TypedMixin,qudi.util.descriptors.DefaultAttributeExtension of DefaultAttribute including type checking via isinstance. A given default value is not type-checked.
Example usage:
- class Test:
variable_a = TypedAttribute([int, float]) variable_b = TypedAttribute([str], None) def __init__(self):
assert self.variable_b is None self.variable_a = 42 self.variable_b = ‘hello world’ assert self.variable_a == 42 assert self.variable_b == ‘hello world’ # The following would raise TypeError # self.variable_a = self.variable_b = None
- __init__(valid_types: ~typing.Iterable[~typing.Type] | None = None, default: ~typing.Any | None = <object object>)[source]
Methods
__init__([valid_types, default])check_type(value)- check_type(value: Any) None