pypz.core.specs.utils module
- class pypz.core.specs.utils.AccessWrapper(instance, *args, **kwargs)
Bases:
object
This class wraps the access of the provided object’s protected and private attributes into publicly accessible methods.
- PATTERN = '^(_[a-zA-Z0-9]+__|_(?!_))'
- _SingletonAccessWrapper__singletons: dict[int, AccessWrapper] = {}
- get_nested_instance(name)
- has_nested_instance(name)
- pypz.core.specs.utils.ExcludedCascadingParameterPrefix = '>'
This strings denotes a cascading parameter. Excluded cascading parameter means that the model defines this parameter will NOT get it provided ONLY the sub instances.
- pypz.core.specs.utils.IncludedCascadingParameterPrefix = '#'
This strings denotes a cascading parameter. Included cascading parameter means that the model defines this parameter will get it provided as well the sub instances.
- class pypz.core.specs.utils.InstanceParameters(*args, **kwargs)
Bases:
dict
This class represents the parameters of the instance organized into a dictionary. The necessity of extending the builtin dict is that the parameter changes shall be watched because the expected parameters that are represented by instance attributes shall be updated as well, so we need to be able to define callbacks on parameter set. The mentioned default callbacks are defined in the Instance class.
- on_parameter_update(name, callback: Callable[[Any], None])
- update([E, ]**F) None. Update D from dict/iterable E and F.
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- class pypz.core.specs.utils.SingletonAccessWrapper
Bases:
type
This metaclass extends the AccessWrapper class with the functionality of caching AccessWrapper objects based on the Instance object. This allows to reuse the AccessWrapper object instead of creating a new one.
- __singletons: dict[int, AccessWrapper] = {}
- pypz.core.specs.utils.load_class_by_name(class_name: str) type
This method loads a class given its name by traversing its module path up to the class itself.
- pypz.core.specs.utils.remove_super_classes(classes: set[type]) set[type]
This function will remove the classes from the set, which are super class for any of the others, hence redundant. It is used to clean up the Instance specs to avoid Deadly Diamond of Death situation at dynamic class creation.
- pypz.core.specs.utils.resolve_dependency_graph(instances: set | Iterable) list[set]
This method can resolve the dependencies along instances provided in the instance set. Dependency can be formulated between instances via depends_on(). Resolution means that the instances will be ordered into a list of sets, where each outer list represents a dependency level and each inner sets hold the instances on that level. For example, if there are instances w/o any dependencies, then those will be placed to level 0, which is the list[0]. On level 1 all the instances are placed that has dependencies to level 0 instances and so on.
- Parameters:
instances – set of instances to resolve the dependencies across
- Returns:
list of sets, where the list represents dependency levels and set the instances on it