Skip to main content

validator

Decorate methods on the class indicating that they should be used to validate fields.

def validator(
__field: str,
*fields: str,
pre: bool = False,
each_item: bool = False,
always: bool = False,
check_fields: bool | None = None,
allow_reuse: bool = False
) - > Callable

Decorate methods on the class indicating that they should be used to validate fields.

Parameters

NameTypeDescription
__fieldstrThe first field the validator should be called on; this is separate from fields to ensure an error is raised if you don't pass at least one.
*fieldsstrAdditional field(s) the validator should be called on.
prebool = FalseWhether this validator should be called before the standard validators (else after).
each_itembool = FalseFor complex objects (sets, lists etc.) whether to validate individual elements rather than the whole object.
alwaysbool = FalseWhether this method and other validators should be called even if the value is missing.
check_fields`boolNone` = None
allow_reusebool = FalseWhether to track and raise an error if another validator refers to the decorated function.

Returns

TypeDescription
CallableA decorator that can be used to decorate a function to be used as a validator.