rwskit.types
Functions
|
Check if the given |
|
Check if a type is optional. |
|
Get the fully qualified name of this class. |
|
Import and return the type object from a fully qualified class name. |
|
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
Uniontype hint or the|operator.- Parameters:
type (Any) – The type to check.
- Returns:
Trueif the given type is a union, otherwiseFalse.- 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
UnioncontainingNone.- Parameters:
type (Any) – The type to check.
- Returns:
Trueiftype_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
clsis 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_nameisNoneor empty.ModuleNotFoundError – If the input
qualified_class_namecannot 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]