Typing#

This module contains all DNIKit custom types.

dnikit.typing.resolve_one_many_or_none(x, cls)[source]#

Convert a OneManyOrNone[_T] to a frozenset of _T or None.

Parameters:
  • x (None | _T | Collection[_T]) – object or collection of objects or None

  • cls (Type[_T]) – type of each object (or type of individual object)

Returns:

frozen set of objects or None

Return type:

AbstractSet[_T] | None

dnikit.typing.resolve_one_or_many(x, cls)[source]#

Convert a OneOrMany[_T] to a frozenset of _T.

Parameters:
  • x (_T | Collection[_T]) – object or collection of objects

  • cls (Type[_T]) – type of each object (or type of individual object)

Returns:

frozen set of objects

Return type:

AbstractSet[_T]

dnikit.typing.resolve_one_or_many_to_list(x, cls)[source]#

Convert a OneOrMany[_T] to a list of _T.

Parameters:
  • x (_T | Collection[_T]) – object or collection of objects

  • cls (Type[_T]) – type of each object (or type of individual object)

Returns:

list of objects

Return type:

List[_T]

dnikit.typing.resolve_path_or_str(x)[source]#

Convert a pathlib.Path or string path into a pathlib Path

Parameters:

x (str | Path) – pathlib.Path or str pathname

Returns:

pathlib.Path instance of the path

Return type:

Path

dnikit.typing.OneOrMany#

alias of Union[_T, Collection[_T]]

dnikit.typing.OneManyOrNone#

alias of Union[None, _T, Collection[_T]]

dnikit.typing.PathOrStr#

alias of Union[str, pathlib.Path]

dnikit.typing.StringLike#

alias of Any. Similar to “array like” – these are types that can be losslessly converted to/from string and they might be used as Identifiers in a Batch.