Skip to content

bagof.converters.collections

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

Classes

ToIterable

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

Bases: Converter[ITERABLE, Any]

Converter for abc.Iterable.

Methods:

like
like(__reentrant: tuple = ()) -> Any

Return the input hint for this converter.

__call__
__call__(value: Any) -> ITERABLE

Convert the value to an iterable, converting each element.

ToSequence

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

Bases: Converter[SEQUENCE, Any]

Converter for abc.Sequence.

Methods:

like
like(__reentrant: tuple = ()) -> Any

Return the input hint for this converter.

__call__
__call__(value: Any) -> SEQUENCE

Convert the value to a sequence, converting each element.

ToSet

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

Bases: ToIterable

Converter for [abc.Set][bagof.converters.collections.abc.Set].

Sets convert element-wise like any other iterable.

Note

The only difference from ToIterable is the concrete fallback, so that an abstract Set[int] hint still produces a real container (frozenset, since abc.Set is immutable) rather than a bare iterator.

ToMutableSet

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

Bases: ToSet

Converter for [abc.MutableSet][bagof.converters.collections.abc.MutableSet].

ToMapping

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

Bases: Converter[MAPPING, Any]

Converter for abc.Mapping.

Methods:

like
like(__reentrant: tuple = ()) -> Any

Return the input hint for this converter.

__call__
__call__(value: Any) -> MAPPING

Convert the value to a mapping, converting each key and value.

ToTuple

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

Bases: Converter[TUPLE, Any]

Converter for tuple.

Methods:

like
like(__reentrant: tuple = ()) -> Any

Return the input hint for this converter.

__call__
__call__(value: Any) -> TUPLE

Convert the value to a tuple, converting each element.

ToLength

ToLength(length: int, hint: Any = UNSET)

Bases: ToSequence[ITERABLE]

Converter for sequences of a fixed length.

Parameters:

Name Type Description Default
length int

The expected length of the sequence.

required
hint Any

The type hint to convert to.

UNSET

Methods:

__call__
__call__(value: Any) -> ITERABLE

Convert the value to a sequence and check its length.