Skip to content

bagof.validators.collections

Validators for collection types (list, tuple, dict, etc.).

Classes

IsIterable

IsIterable(hint: Any = UNSET, compose: bool = False)

Bases: Validator[ITERABLE]

Validator for abc.Iterable.

Note

When parameterized (e.g. Iterable[int]), each element is validated against the argument type. This requires the value to be an abc.Sequence (e.g. a list), since a one-shot iterator or generator cannot be safely re-validated; a bare generator raises a TypeValidationError in that case.

IsSequence

IsSequence(hint: Any = UNSET, compose: bool = False)

Bases: IsIterable[SEQUENCE]

Validator for abc.Sequence.

IsMapping

IsMapping(hint: Any = UNSET, compose: bool = False)

Bases: Validator[MAPPING]

Validator for abc.Mapping.

IsTupleIsh

IsTupleIsh(hint: Any = UNSET, compose: bool = False)

Bases: Validator[TUPLE]

Per-item validator for sequence (not necessarily tuple) containers.

Note

This validator is not registered by default, so it is only used when instantiated explicitly.

IsTuple

IsTuple(hint: Any = UNSET, compose: bool = False)

Bases: IsTupleIsh[TUPLE]

Validator for tuple.

IsDict

IsDict(hint: Any = UNSET, compose: bool = False)

Bases: IsMapping[MAPPING]

Validator for dict.

IsTypedDict

IsTypedDict(hint: Any = UNSET, compose: bool = False)

Bases: IsMapping[MAPPING]

Validator for TypedDict.

HasLength

HasLength(length: int, hint: Any = UNSET, compose: bool = False)

Bases: IsSequence[ITERABLE]

Validator for abc.Sequence, that checks its length.

Note

This validator is not registered by default, so it is only used when instantiated explicitly, e.g. HasLength(3).

Parameters:

Name Type Description Default
length int

The expected length of the sequence.

required
hint Any

The type hint to validate against.

UNSET
compose bool

Whether to compose this validator with others, when they are found in Annotated metadata.

False

Methods: