argclz.validator.ListValidatorBuilder#

class argclz.validator.ListValidatorBuilder[source]#

Bases: AbstractTypeValidatorBuilder[list[T]]

a list validator

__init__(element_type=None)[source]#
Parameters:

element_type (type[T] | Validator | None)

Methods Summary

__init__([element_type])

allow_empty([allow])

Allow or disallow empty lists

freeze()

(internal use) return a copy of itself.

length_in_range(a, b, /)

Enforce a length range for lists

on_item(validator)

Apply an additional validator to each item in the list

optional()

__call__(value)

Details

freeze()[source]#

(internal use) return a copy of itself.

Return type:

Self

length_in_range(a, b, /)[source]#

Enforce a length range for lists

Parameters:
  • a (int | None)

  • b (int | None)

Return type:

Self

allow_empty(allow=True)[source]#

Allow or disallow empty lists

Parameters:

allow (bool)

Return type:

Self

on_item(validator)[source]#

Apply an additional validator to each item in the list

Parameters:

validator (Callable[[Any], bool]) – A callable that validates each item

Return type:

Self

__call__(value)[source]#
Parameters:

value (Any) – type-casted value.

Returns:

True if value pass the validation.

Raises:

ValueError – when value does not pass the validation.

Return type:

bool

optional()#
Return type:

Self