pyrot.eye_modelling.datamodels.validators#
Data validation and field descriptors for pyROT data models.
Exceptions#
Exception raised when a validation error occurs. |
Classes#
A descriptor class that provides validation for a RayOcular field. |
|
Three-dimensional vector with components of a given type. |
Functions#
|
Validate dataclasses. |
|
Validate positive floats. |
|
Validate Vector3 objects. |
|
Validate literal values. |
|
Validate optional values. |
Module Contents#
- exception pyrot.eye_modelling.datamodels.validators.ValidationError(value: Any, field_name: str)#
Bases:
ExceptionException raised when a validation error occurs.
- class pyrot.eye_modelling.datamodels.validators.RayOcularField(validator: Callable[[Any], Value], name: str, *, default: Value = ...)#
Bases:
ValidatedField[Value]A descriptor class that provides validation for a RayOcular field.
Parameters#
- validatorCallable[[Any], Value]
A callable object that performs the validation.
- namestr
The RayOcular name of the field. This is used for serialization and deserialization to RayOcular.
- defaultValue, optional
The default value for the field. If not provided, the field will be required and must be set explicitly.
Attributes#
- public_namestr
The public name of the field.
- private_namestr
The private name of the field.
Methods#
- __get__(self, instance: Instance, owner: type[Instance] | None = None) -> Value:
Retrieves the value of the field.
- __set__(self, instance: Instance, value: Value):
Sets the value of the field after validating it.
- validate(self, value):
Validates the given value using the provided validator.
Raises#
- ValueError
If the validation fails.
Notes#
Define a ValidatedField descriptor for a class attribute and provide a validator function. The validator function should take a single argument and return the validated value.
Examples#
>>> class Person: ... age = ValidatedField(int) ... ... def __init__(self, age): ... self.age = age
- pyrot.eye_modelling.datamodels.validators.dataclass(cls: type[T]) Callable[Ellipsis, T]#
Validate dataclasses.
Checks if the value is an instance of the dataclass or a dict that can be used to create an instance of the dataclass.
Parameters#
- clstype[T]
The dataclass type to validate against.
Returns#
- Callable[…, T]
A validator function that can be used to validate instances of the dataclass.
- pyrot.eye_modelling.datamodels.validators.positive_float(value: Any) float#
Validate positive floats.
Parameters#
- valueAny
The value to validate.
Returns#
- float
The validated positive float value.
Raises#
- ValueError
If the value is not a positive float.
- class pyrot.eye_modelling.datamodels.validators.Vector3#
Bases:
Generic[T]Three-dimensional vector with components of a given type.
Attributes#
- xT
X component of the vector.
- yT
Y component of the vector.
- zT
Z component of the vector.
- pyrot.eye_modelling.datamodels.validators.vector3(item_validator: Callable[Ellipsis, T]) Callable[[Any], Vector3[T]]#
Validate Vector3 objects.
Parameters#
- item_validatorCallable[…, T]
A validator function for the individual components of the vector.
Returns#
- Callable[[Any], Vector3[T]]
A validator function that can be used to validate Vector3 objects.