metron_shared.structures module#
This module provides data structures/patterns (classes or decorators).
- class metron_shared.structures.Singleton(decorated_object: Any)#
Bases:
object
Represents singleton data pattern applicable on class / function / method . When applied on a class, only one instance of the class is allowed for whole program lifespan. When applied on a function / method , only one call is allowed for whole program lifespan. The decorator can be applied on more classes / functions / methods, not only on one object of the program. It does not change decorated object.
- _called#
Set data structure which keeps one use across classes / functions / methods.
- Type:
Set[Any]
- _function#
Class / function / method on which the decorator is applied.
- Type:
Any
- __annotations__ = {'_called': typing.Set[typing.Any]}#
- __call__(*args: Any, **kwargs: Any) → Any#
It checks if decorated object was not already instantiated or called. If does not, it allows to create / call it. The method is called when decorator is applied on class / function / method.
- Parameters:
*args (Any) – Positional arguments.
**kwargs (Any) – Key-worded arguments.
Returns (Typing.Any): Decorated object itself without change.
- Exceptions:
Exception: Violence of singleton paradigm of decorated object.
- __get__(instance: Any, owner: Any) → Any#
The method is needed to work with class method.
- Parameters:
instance (Any) – Class instance.
owner (Any) – Instance class owner.
Returns (typing.Any):
- Exceptions:
Exception: Violence of singleton paradigm of decorated object.
- __init__(decorated_object: Any)#
Saves decorated object as attribute, for later lookup.
- Parameters:
decorated_object (Any) – Decorated object.
- _called: Set[Any] = {<function set_hydra_config>}#