rwskit.types

Functions

is_union(→ bool)

Check if the given type_ is a union of types.

is_optional(→ bool)

Check if a type is optional.

get_qualified_name(→ str)

Get the fully qualified name of this class.

type_from_string(→ type)

Import and return the type object from a fully qualified class name.

import_all_modules_in_path(→ dict[str, types.ModuleType])

Import all modules in a given path and return a dict of their names and modules.

Module Contents

rwskit.types_.is_union(type_: Any) bool[source]

Check if the given type_ is a union of types.

A type can be a union if it uses the Union type hint or the | operator.

Parameters:

type (Any) – The type to check.

Returns:

True if the given type is a union, otherwise False.

Return type:

bool

rwskit.types_.is_optional(type_: Any) bool[source]

Check if a type is optional.

An optional type is either defined by class:typing.Optional or by a Union containing None.

Parameters:

type (Any) – The type to check.

Returns:

True if type_ is optional.

Return type:

bool

rwskit.types_.get_qualified_name(cls: type) str[source]

Get the fully qualified name of this class.

The fully qualified name is the full path of package names, the module name, and class name.

Parameters:

cls (Type[Any])

Returns:

The fully qualified name of this class.

Return type:

str

Raises:

icontract.ViolationError – If the input cls is not a type.

rwskit.types_.type_from_string(qualified_class_name: str) type[source]

Import and return the type object from a fully qualified class name.

Parameters:

qualified_class_name (str) – The fully qualified class name.

Returns:

The type object corresponding to the fully qualified class name.

Return type:

type

Raises:
  • icontract.ViolationError – If the input qualified_class_name is None or empty.

  • ModuleNotFoundError – If the input qualified_class_name cannot be loaded.

rwskit.types_.import_all_modules_in_path(module_path: str) dict[str, types.ModuleType][source]

Import all modules in a given path and return a dict of their names and modules.

Parameters:

module_path (str) – The full path to the module, e.g. foo.bar.baz

Returns:

A dictionary mapping the module path segments to their corresponding modules.

Return type:

dict[str, ModuleType]