pypz.core.specs.utils module

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.Internals(instance)

Bases: object

This helper class realizes a thin wrapper around an Instance object allowing the access of protected and private attributes as they were public. It is just a convenience feature to hide these getters from the users in a way any linter can live with it.

Notice that it relies on a class variable called ‘_internal_access’, which specifies the accessible attributes. If the Instance is being extended, then every child classes can define that class variable, since all those fields will be resolved in a reverse order dynamically.

Parameters:

instance – the instance object to access internals from

_collect_allowed_names() set[str]

This method collects all the available names specified through ‘_internal_access’ field on the classes. It resolves them in a reserve order in the inheritance.

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