pic_scanner.helpers.properties
Classes
A descriptor class that restricts the setting of a property based on type, value, and custom conditions. |
Functions
|
Decorator to ensure that a property setter only accepts floats between a given range. |
|
Module Contents
- pic_scanner.helpers.properties.validate_float_between(min_value: float = 0.0, max_value: float = 1.0)
Decorator to ensure that a property setter only accepts floats between a given range.
- Parameters:
min_value (Union[float, int], optional) – The minimum value that the property can be.
max_value (Union[float, int], optional) – The maximum value that the property can be.
- Returns:
The decorated function.
- Return type:
function
- Raises:
ValueError – If the value is not between the specified range.
Examples
>>> class Test: ... @validate_float_between(0.0, 1.0) ... def test(self, value): ... return value ... >>> t = Test() >>> t.test(0.5) 0.5 >>> t.test(1.5) Traceback (most recent call last): ... AttributeError: Value must be between 0.0 and 1.0
- class pic_scanner.helpers.properties.ReactiveProperty(default_value=None, callback=None, *args, **kwargs)
- add_callback(callback, *args, **kwargs)
- class pic_scanner.helpers.properties.FrozenProperty(*args, **kwargs)
Bases:
inspyre_toolbox.syntactic_sweets.properties.RestrictedSetterA descriptor class that restricts the setting of a property based on type, value, and custom conditions.
This class is designed to be used as a descriptor for class properties, allowing for the definition of restrictions on the setting of the property. These restrictions can include type checking, value checking, and custom conditions that must be met for the property to be set. If any of the restrictions are violated, an exception is raised.
The RestrictedSetter class also allows for the definition of an initial value for the property, which is used if the property has not been set. This can be useful for defining default values for properties.
Notes
If a preferred_type is specified, the value will be converted to that type if possible. If the value cannot be converted to the preferred type, a TypeError will be raised.
If a custom condition is specified, the condition must be met for the property to be set. If the condition is not met, an UnmetConditionError will be raised.
If an exception is specified, it will be raised instead of the default UnmetConditionError if the custom condition is not met.
If allowed_values is specified, the value must be in the set of allowed values for the property to be set. If the value is not in the set, a ValueError will be raised.
If restrict_setter is set to True, the setter can only be called within class methods. If the setter is called outside of class methods, a PermissionError will be raised.
- pic_scanner.helpers.properties.freeze_property(cls)