utils

validators.utils.ValidationError(function: Callable[[...], Any], arg_dict: Dict[str, Any], message: str = '')

Exception class when validation failure occurs.

validators.utils.validator(func: Callable[[...], Any])

A decorator that makes given function validator.

Whenever the given func returns False this decorator returns ValidationError object.

Examples

>>> @validator
... def even(value):
...     return not (value % 2)
>>> even(4)
True
>>> even(5)
ValidationError(func=even, args={'value': 5})
Parameters:

func – Function which is to be decorated.

Returns:

A decorator which returns either ValidationError or Literal[True].

Return type:

(Callable[…, ValidationError | Literal[True]])

Raises:

(ValidationError) – If r_ve or RAISE_VALIDATION_ERROR is True