rail.projects.dynamic_class module
- class rail.projects.dynamic_class.DynamicClass[source]
Bases:
objectBase class for classes that will create objects of sub-classes dynamically
This implements:
keeping track of all the loaded sub-classes,
being able to load a new sub-class from the python module and class name
being able to create an object of sub-class from a dict
Subclasses that serve as parent classes to several addtional sub-classes should
override the sub_classes to keep track of their sub-classes
- classmethod create_from_dict(config_dict)[source]
Create a DynamicClass object of type T
- Return type:
TypeVar(T, bound= DynamicClass)- Parameters:
config_dict (dict[str, Any],) – Configuration parameters
- Returns:
Newly created object
- Return type:
T
Notes
config_dict must include ‘class_name’ which gives the path and name of the class, e.g., rail.plotters.some_file.SomeClass
- classmethod get_sub_class(key, class_name=None)[source]
Get a particular sub-class of DynamicClass by name
- Return type:
type[TypeVar(T, bound= DynamicClass)]- Parameters:
key (str) – Key for the subclass.
class_name (str | None = None) – Full class name, so it can be loaded
- Returns:
Subclass in question
- Return type:
type
- classmethod load_sub_class(class_name)[source]
Import a particular sub-class of DynamicClass by name
- Return type:
type[TypeVar(T, bound= DynamicClass)]- Parameters:
class_name (str) – Full path and name of the subclass, e.g., rail.plotting.some_file.SomeClass
- Returns:
Subclass in question
- Return type:
type
- classmethod print_classes()[source]
Print the sub-classes of DynamicClass that have been loaded
- Return type:
None
-
sub_classes:
dict[str,type[DynamicClass]] = {}