dantro.utils.link module¶
Implements the Link class
-
class
dantro.utils.link.Link(*, anchor: TGroupOrContainer, rel_path: str)[source]¶ Bases:
dantro.mixins.general.ForwardAttrsMixinA link is a connection between two objects in the data tree, i.e. a data group and a data container.
It has a source object that it is coupled to and a relative path from that object to the target object.
Whenever attribute access occurs, an object of this class will resolve the linked object (if not already cached) and then forward the attribute call to that object.
-
FORWARD_ATTR_TO= 'target_object'¶
-
__init__(*, anchor: TGroupOrContainer, rel_path: str)[source]¶ Initialize a link from an anchor and a relative path to a target
-
property
target_weakref¶ Resolve the target and return the weak reference to it
-
property
target_object¶ Return a (non-weak) reference to the actual target object
-
property
anchor_weakref¶ Resolve the weak reference to the anchor and return it, i.e.: return a reference to the actual object.
-
property
anchor_object¶ Return a (non-weak) reference to the anchor object
-
property
target_rel_path¶ Returns the relative path to the target
-
_forward_attr_get_forwarding_target()[source]¶ Get the object that the attribute call is to be forwarded to, i.e. the resolved target object. This invokes resolution of the target and caching of the corresponding weakref, but the returned (strong) ref will not be cached.
-
FORWARD_ATTR_EXCLUDE= ()¶
-
FORWARD_ATTR_ONLY= None¶
-
_Link__resolve_target_ref() → None¶ Resolves the weak reference to the target object and caches it
-
__getattr__(attr_name: str)¶ Forward attributes that were not available in this class to some other attribute of the group or container.
- Parameters
attr_name (str) – The name of the attribute that was tried to be accessed but was not available in
self.- Returns
The attribute
attr_nameof getattr(self, self.FORWARD_ATTR_TO)
-
_forward_attr_post_hook(attr)¶ Invoked before attribute forwarding occurs
-
_forward_attr_pre_hook(attr_name: str = None)¶ Invoked before attribute forwarding occurs
-