bagof.validators.collections
Validators for collection types (list, tuple, dict, etc.).
Classes
IsIterable
Validator for abc.Iterable.
Note
When parameterized (e.g. Iterable[int]), each element is
validated against the argument type. A one-shot iterator or
generator cannot be checked this way -- walking it would consume
the value being validated -- so it raises a
TypeValidationError instead.
IsSequence
IsIterator
Bases: IsIterable[ITERABLE]
Validator for Iterator.
Only the container type is checked. An iterator yields itself from
__iter__, so walking it to check elements would consume the very
value being validated -- a parameterized hint like Iterator[int]
therefore passes any iterator, and its elements are left unchecked.
IsSet
Bases: IsIterable[ITERABLE]
Validator for Set.
A set is finite and re-iterable, so a parameterized hint
(e.g. Set[int]) checks every member.
IsFrozenSet
IsMutableSet
IsMapping
IsTupleIsh
IsTuple
IsDict
IsTypedDict
HasLength
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 |
False
|