argclz.validator.ValidatorBuilder#

final class argclz.validator.ValidatorBuilder[source]#

Bases: object

__init__()#

Methods Summary

__init__()

all(*validator)

return a validator that ensure all combined validator are satisfied.

any(*validator)

return a validator that ensure at least one combined validator is satisfied.

list([element_type])

a list validator

non_none()

optional()

return a validator that pass the validation when the value is None.

tuple()

a tuple validator

__call__(validator[, message])

Create a validator with a failure message.

Attributes Summary

float

a float validator

int

a int validator

path

a path validator

str

a str validator

Details

property str: StrValidatorBuilder#

a str validator

property int: IntValidatorBuilder#

a int validator

property float: FloatValidatorBuilder#

a float validator

tuple(*element_type: int | ellipsis) TupleValidatorBuilder[source]#
tuple(*element_type: type[T] | ellipsis | None) TupleValidatorBuilder

a tuple validator

overloading element_type example:

  • 2: 2-length tuple

  • type1, type2: 2-length tuple with type1 at pos 0 and type2 at pos 1.

  • type1, None: 2-length tuple with type1 at pos 0 and any type at pos 1.

  • type1, ...: at-least-1-length tuple with type1 from pos 0 to remaining pos.

list(element_type=None)[source]#

a list validator

Parameters:

element_type (type[T] | Validator | None) – element type.

Returns:

Return type:

ListValidatorBuilder

property path#

a path validator

classmethod all(*validator)[source]#

return a validator that ensure all combined validator are satisfied. return an always-true validator if validator is empty.

Parameters:

validator (Callable[[T], bool])

Return type:

AndValidatorBuilder

classmethod any(*validator)[source]#

return a validator that ensure at least one combined validator is satisfied. return an always-true validator if validator is empty.

Parameters:

validator (Callable[[T], bool])

Return type:

OrValidatorBuilder

classmethod optional()[source]#

return a validator that pass the validation when the value is None.

Return type:

Validator

classmethod non_none()[source]#
Return type:

Validator

__call__(validator, message=None)[source]#

Create a validator with a failure message.

Parameters:
  • validator (Callable[[Any], bool]) – callable

  • message (str | Callable[[Any], str] | None) – failure message. It could be a str message that contains one %-formating expression (for example: ‘%s’), or a callable (T)->str.

Returns:

a validator

Return type:

LambdaValidator