CADETProcess.dataStructure.parameter.Typed

Contents

CADETProcess.dataStructure.parameter.Typed#

class CADETProcess.dataStructure.parameter.Typed(*args, ty=None, **kwargs)[source]#

Mixin for parameters constrained to a specific type.

Typed extends the base Parameter class with type constraints. When instantiated with a specific type (ty), it ensures values are of that type or can be cast to that type. If ty is not specified during instantiation and is not predefined by a subclass, an error is raised.

See also

Parameter
Bool
Integer
Tuple
Float
String
Dictionary

Notes

  • If ty is specified during instantiation, any value assigned to this parameter undergoes validation against this type.

  • Override cast_value in subclasses for custom casting logic.

  • Assigning None to the parameter removes its current value from the instance.

  • An error is raised during instantiation if ty is neither provided nor predefined by a subclass.

Attributes:
tytype

Desired type for the parameter. Defaults to accepting any type. Subclasses can directly set this attribute.

Methods

cast_value(value) -> Any:

Attempts to cast the value to the target type. By default, returns the value as is. Subclasses can override for specific casting behavior.

_prepare(instance, value, recursive=False) -> Any:

Prepares and optionally type-casts the value before checking its type. This method uses cast_value to attempt to cast the value to the required type.

_check(instance, value, recursive=False) -> bool:

Validates if the value matches the desired type (ty). Raises a TypeError if validation fails.