Skip to content

Typing utils

DataModule #

Bases: Protocol[BatchType]

Protocol that shows the minimal attributes / methods of the LightningDataModule class.

This is used to type hint the batches that are yielded by the DataLoaders.

is_list_of #

is_list_of(
    object: Any, item_type: type[V] | tuple[type[V], ...]
) -> TypeGuard[list[V]]

Used to check (and tell the type checker) that object is a list of items of this type.

is_sequence_of #

is_sequence_of(
    object: Any, item_type: type[V] | tuple[type[V], ...]
) -> TypeGuard[Sequence[V]]

Used to check (and tell the type checker) that object is a sequence of items of this type.

is_mapping_of #

is_mapping_of(
    object: Any, key_type: type[K], value_type: type[V]
) -> TypeGuard[Mapping[K, V]]

Used to check (and tell the type checker) that object is a mapping with keys and values of the given types.