utils.namespace_tools¶
Tools for programatically manipulating / adding to the namespace.
-
class
borch.utils.namespace_tools.
AugmentedClassMap
¶ Container of how the augmented classes are mapped
-
property
augmented
¶ Alias for field number 2
-
property
name
¶ Alias for field number 0
-
property
original
¶ Alias for field number 1
-
property
-
borch.utils.namespace_tools.
create_augmented_classes
(module: object, parent: type, class_factory: callable, ignore: Optional[List[object]] = None) → List[borch.utils.namespace_tools.AugmentedClassMap]¶ Using class_factory, create modified classes of any subclasses of parent found in module and set them in the namespace of caller.
- Parameters
caller – The name of the caller module (available as __name__).
module – The module to search for subclasses of parent.
parent – The parent class for discovering classes to augment.
class_factory – A callable which receives a class, performs operations with that class, then returns a new class.
Notes
Type of module should be module, but this is not available through the builtins or typing library…
-
borch.utils.namespace_tools.
create_module
(name, description, context=None)¶ Dynamically create a python module
-
borch.utils.namespace_tools.
extend_module
(caller: str, mappings: List[borch.utils.namespace_tools.AugmentedClassMap])¶ Add attributes to a python module that is already imported.
-
borch.utils.namespace_tools.
get_instances
(module, instance)¶ Get the members of a module which are instances of instance.
- Parameters
module –
The module to find instances within.
- instance: The parent class to search for subclasses of. NB parent
itself will also be filtered out.
- Returns
A list of instances of instance exported from module module.
-
borch.utils.namespace_tools.
get_subclass_members
(module, parent)¶ Get the members of a module which are subclasses of parent, excluding parent itself.
- Parameters
module – The module to find classes within.
parent – The parent class to search for subclasses of. NB parent itself will also be filtered out.
- Returns
A list of subclasses of parent exported from module module.