dantro.mixins.general module

This module implements general mixin classes for containers and groups

class dantro.mixins.general.ForwardAttrsMixin[source]

Bases: object

This Mixin class forwards all calls to unavailable attributes to a certain other attribute, specified by FORWARD_ATTR_TO class variable.

By including naive __getstate__ and __setstate__ methods, classes that include this mixin remain pickleable.

FORWARD_ATTR_TO = None
FORWARD_ATTR_ONLY = None
FORWARD_ATTR_EXCLUDE = ()
__getstate__() → dict[source]

Returns the object’s __dict__

__setstate__(d: dict)[source]

Sets the object’s __dict__ to the given one

__getattr__(attr_name: str)[source]

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)

_forward_attr_pre_hook(attr_name: str = None)[source]

Invoked before attribute forwarding occurs

_forward_attr_get_forwarding_target()[source]

Get the object that the attribute call is to be forwarded to

_forward_attr_post_hook(attr)[source]

Invoked before attribute forwarding occurs

class dantro.mixins.general.ForwardAttrsToDataMixin[source]

Bases: dantro.mixins.general.ForwardAttrsMixin

This Mixin class forwards all calls to unavailable attributes to the data attribute (a property) and thus allows to replace all behaviour that is not implemented in the group or container with that of the stored data.

FORWARD_ATTR_TO = 'data'
FORWARD_ATTR_EXCLUDE = ()
FORWARD_ATTR_ONLY = None
__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)

__getstate__() → dict

Returns the object’s __dict__

__setstate__(d: dict)

Sets the object’s __dict__ to the given one

_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