[docs]classTrueFuse(StateValidator[bool]):""" A StateValidator that can only be initialized to True or False, and can only be modified to True. """
[docs]defvalidate_value(self,value:Any)->bool:""" Validates the initial value, ensuring it is a boolean. Args: value (Any): The initial value. Returns: bool: The validated value. Raises: TypeValidationError: If the value is not a boolean. """ifnotisinstance(value,bool):raiseTypeValidationError("TrueFuse can only be initialized to True or False")returnvalue
[docs]defvalidate_modifications(self,new_value:Any)->True:""" Validates the modification to the value, ensuring it is set to True. Args: new_value (Any): The new value to be set. Raises: InvalidModificationError: If the new value is not True. """ifnew_valueisnotTrue:raiseInvalidModificationError("TrueFuse can only be modified to True")returnTrue