dantro.containers.link module¶
Implements the Link class and the LinkContainer.
-
class
dantro.containers.link.
LinkContainer
(*, name: str, data, attrs=None)[source]¶ Bases:
dantro.mixins.base.CheckDataMixin
,dantro.containers.general.PassthroughContainer
A LinkContainer is a container containing a Link object.
It forwards all attribute calls to the Link object, which in turn forwards all attribute calls to the linked object, thereby emulating the behaviour of the linked object.
-
DATA_EXPECTED_TYPES
= (<class 'dantro.utils.link.Link'>,)¶
-
_format_info
() → str[source]¶ A __format__ helper function: returns info about the item
In this case, the anchor and relative path of the associated link is returned.
-
DATA_ALLOW_PROXY
= False¶
-
DATA_UNEXPECTED_ACTION
= 'warn'¶
-
FORWARD_ATTR_EXCLUDE
= ()¶
-
FORWARD_ATTR_ONLY
= None¶
-
FORWARD_ATTR_TO
= 'data'¶
-
_ATTRS_CLS
¶ alias of
dantro.base.BaseDataAttrs
-
__delitem__
(key)¶ Deletes an item
-
__eq__
(other) → bool¶ Evaluates equality by making the following comparisons: identity, strict type equality, and finally: equality of the
_data
and_attrs
attributes, i.e. the private attribute. This ensures that comparison does not trigger any downstream effects like resolution of proxies.If types do not match exactly,
NotImplemented
is returned, thus referring the comparison to the other side of the==
.
-
__format__
(spec_str: str) → str¶ Creates a formatted string from the given specification.
Invokes further methods which are prefixed by
_format_
.
-
__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_name
of getattr(self, self.FORWARD_ATTR_TO)
-
__getitem__
(key)¶ Returns an item.
-
__getstate__
() → dict¶ Returns the object’s
__dict__
-
__init__
(*, name: str, data, attrs=None)¶ Initialize a BaseDataContainer, which can store data and attributes.
- Parameters
name (str) – The name of this data container
data – The data to store in this container
attrs (None, optional) – A mapping that is stored as attributes
-
__repr__
() → str¶ Same as __str__
-
__setitem__
(key, val)¶ Sets an item.
-
__setstate__
(d: dict)¶ Sets the object’s
__dict__
to the given one
-
__sizeof__
() → int¶ Returns the size of the data (in bytes) stored in this container’s data and its attributes.
Note that this value is approximate. It is computed by calling the
sys.getsizeof
function on the data, the attributes, the name and some caching attributes that each dantro data tree class contains. Importantly, this is not a recursive algorithm.Also, derived classes might implement further attributes that are not taken into account either. To be more precise in a subclass, create a specific __sizeof__ method and invoke this parent method additionally.
For more information, see the documentation of
sys.getsizeof
:
-
__str__
() → str¶ An info string, that describes the object. This invokes the formatting helpers to show the log string (type and name) as well as the info string of this object.
-
_abc_impl
= <_abc_data object>¶
-
_attrs
= None¶
-
_check_data
(data) → None¶ A general method to check the received data for its type
- Parameters
data – The data to check
- Raises
TypeError – If the type was unexpected and the action was ‘raise’
ValueError – Illegal value for DATA_UNEXPECTED_ACTION class variable
- Returns
None
-
_check_name
(new_name: str) → None¶ Called from name.setter and can be used to check the name that the container is supposed to have. On invalid name, this should raise.
This method can be subclassed to implement more specific behaviour. To propagate the parent classes’ behaviour the subclassed method should always call its parent method using super().
- Parameters
new_name (str) – The new name, which is to be checked.
-
_format_cls_name
() → str¶ A __format__ helper function: returns the class name
-
_format_logstr
() → str¶ A __format__ helper function: returns the log string, a combination of class name and name
-
_format_name
() → str¶ A __format__ helper function: returns the name
-
_format_path
() → str¶ A __format__ helper function: returns the path to this container
-
_forward_attr_get_forwarding_target
()¶ Get the object that the attribute call is to be forwarded to
-
_forward_attr_post_hook
(attr)¶ Invoked before attribute forwarding occurs
-
_forward_attr_pre_hook
(attr_name: str = None)¶ Invoked before attribute forwarding occurs
-
_item_access_convert_list_key
(key)¶ If given something that is not a list, just return that key
-
property
attrs
¶ The container attributes.
-
property
classname
¶ Returns the name of this DataContainer-derived class
-
property
data
¶ The stored data.
-
property
logstr
¶ Returns the classname and name of this object
-
property
name
¶ The name of this DataContainer-derived object.
-
property
parent
¶ The associated parent of this container or group
-
property
path
¶ The path to get to this container or group from some root path
-