krrood.utils#
Attributes#
Exceptions#
A base exception class for dataclass-based exceptions. |
Functions#
|
|
|
Returns the full name of a class, including the module name. |
|
Calculate the inheritance path length between two classes. |
|
|
|
Return the default value for a given field in a dataclass. |
|
Return a dict mapping field names to their default values. |
Module Contents#
- krrood.utils.T#
- krrood.utils.recursive_subclasses(cls: Type[T]) List[Type[T]]#
- Parameters:
cls – The class.
- Returns:
A list of the classes subclasses without the class itself.
- exception krrood.utils.DataclassException#
Bases:
ExceptionA base exception class for dataclass-based exceptions. The way this is used is by inheriting from it and setting the message field in the __post_init__ method, then calling the super().__post_init__() method.
- message: str = None#
- krrood.utils.get_full_class_name(cls)#
Returns the full name of a class, including the module name.
- Parameters:
cls – The class.
- Returns:
The full name of the class
- krrood.utils.inheritance_path_length(child_class: Type, parent_class: Type) int | None#
Calculate the inheritance path length between two classes. Every inheritance level that lies between child_class and parent_class increases the length by one. In case of multiple inheritance, the path length is calculated for each branch and the minimum is returned.
- Parameters:
child_class – The child class.
parent_class – The parent class.
- Returns:
The minimum path length between child_class and parent_class or None if no path exists.
- krrood.utils.module_and_class_name(t: Type | _SpecialForm) str#
- krrood.utils.get_default_value(dataclass_type, field_name)#
Return the default value for a given field in a dataclass.
- Parameters:
dataclass_type – The dataclass type to get the default value for.
field_name – The name of the field to get the default value for.
- Returns:
The default value for the field.
- krrood.utils.get_default_values_for_dataclass(dataclass_type)#
Return a dict mapping field names to their default values. Only includes fields that actually define a default.
- Parameters:
dataclass_type – The dataclass type to get the default values for.
- Returns:
A dict mapping field names to their default values.