smarts.core.utils.type_operations module
- class smarts.core.utils.type_operations.TypeSuite(base_type: Type[T])[source]
A utility that manages sub-classes of the given base type.
- Parameters:
base_type (Type[T]) – The base type this suite will manage.
- clear_type(type_to_clear: Type)[source]
Clear all instances of the given type from this suite. This includes all sub-classes. This should be an sub-class of the type that this suite manages.
- Parameters:
type_to_clear (Type[S]) – The type to clear.
- get_all_by_type(requested_type: Type[S]) List[S] [source]
Gets all instances that are a sub-type of the given type.
- Parameters:
requested_type (Type[T]) – The type to query for.
- Raises:
TypeError – The type is not a sub-class of the type this suite manages.
- Return type:
Optional[T]
- get_by_id(instance_id: str) T | None [source]
Get an instance by its name.
- Parameters:
instance_id (str) – The name of the instance to retrieve.
- Returns:
The instance if it exists.
- Return type:
Optional[T]
- get_by_type(requested_type: Type[T]) T | None [source]
Get an instance of the exact given type.
- Parameters:
requested_type (Type[T]) – The type of instance to find.
- Raises:
TypeError – The type is not a sub-class of the type this suite manages.
- Returns:
The instance if it exists.
- Return type:
Optional[T]
- insert(instance: T)[source]
Adds the instance to the suite of managed instances.
- Parameters:
instance (T) – The instance to add.
- property instances: List[T]
Gets all instances that this suite manages. This will contain all instances that that are instances of the base class T.
- Returns:
A list of instances this suite manages.
- Return type:
List[T]
- remove(instance: T) T [source]
Removes the given instance from the suite.
- Parameters:
instance (T) – The instance to remove.
- Returns:
The removed instance.
- Return type:
T
- remove_by_name(instance_id: str) T [source]
Attempts to remove an instance from the suite by its name.
- Parameters:
instance_id (str) – The instance to remove from the suite.
- Returns:
The instance that was removed.
- Return type:
T
- remove_by_type(requested_type: Type[T]) T [source]
Attempts to remove an instance from the suite by its type.
- Parameters:
requested_type (Type[T]) – The type of instance to remove.
- Raises:
TypeError – The type is not a sub-class of the type this suite manages.
- Returns:
The instance that was removed.
- Return type:
T
- smarts.core.utils.type_operations.get_type_chain(target_subclass: type, target_super_class: type) List[type] [source]
Finds an inheritance chain from the current sub-type to the target super-type.
- Parameters:
target_subclass (type) – The subclass type.
target_super_class (type) – The superclass type.
- Returns:
The inheritance chain from the current class to the target superclass.
- Return type:
List[type]