dantro.mixins.base module¶
This sub-module implements the basic mixin classes that are required in the dantro.base module
-
exception
dantro.mixins.base.UnexpectedTypeWarning[source]¶ Bases:
UserWarningGiven when there was an unexpected type passed to a data container.
-
args¶
-
with_traceback()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
-
class
dantro.mixins.base.AttrsMixin[source]¶ Bases:
objectThis Mixin class supplies the attrs property getter and setter and the private _attrs attribute.
Hereby, the setter function will initialize a BaseDataAttrs-derived object and store it as an attribute. This relays the checking of the correct attribute format to the actual BaseDataAttrs-derived class.
For changing the class that is used for the attributes, an overwrite of the _ATTRS_CLS class variable suffices.
-
_attrs= None¶
-
_ATTRS_CLS= None¶
-
property
attrs¶ The container attributes.
-
-
class
dantro.mixins.base.SizeOfMixin[source]¶ Bases:
objectProvides the __sizeof__ magic method and attempts to take into account the size of the attributes.
-
__sizeof__() → int[source]¶ 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.getsizeoffunction 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:
-
-
class
dantro.mixins.base.LockDataMixin[source]¶ Bases:
objectThis Mixin class provides a flag for marking the data of a group or container as locked.
-
property
locked¶ Whether this object is locked
-
raise_if_locked(*, prefix: str = None)[source]¶ Raises an exception if this object is locked; does nothing otherwise
-
_LockDataMixin__locked= False¶
-
property
-
class
dantro.mixins.base.CollectionMixin[source]¶ Bases:
objectThis Mixin class implements the methods needed for being a Collection.
It relays all calls forward to the data attribute.
-
class
dantro.mixins.base.ItemAccessMixin[source]¶ Bases:
objectThis Mixin class implements the methods needed for getting, setting, and deleting items. It relays all calls forward to the data attribute, but if given a list (passed down from above), it extracts it
-
class
dantro.mixins.base.MappingAccessMixin[source]¶ Bases:
dantro.mixins.base.ItemAccessMixin,dantro.mixins.base.CollectionMixinSupplies all methods that are needed for Mapping access.
All calls are relayed to the data attribute.
-
__contains__(key) → bool¶ Whether the given key is contained in the items.
-
__delitem__(key)¶ Deletes an item
-
__getitem__(key)¶ Returns an item.
-
__iter__()¶ Iterates over the items.
-
__len__() → int¶ The number of items.
-
__setitem__(key, val)¶ Sets an item.
-
_item_access_convert_list_key(key)¶ If given something that is not a list, just return that key
-
-
class
dantro.mixins.base.CheckDataMixin[source]¶ Bases:
objectThis mixin class extends a BaseDataContainer-derived class to check the provided data before storing it in the container.
It implements a general _check_data method, overwriting the placeholder method in the BaseDataContainer, and can be controlled via class variables.
Note
This is not suitable for checking containers that are added to an object of a BaseDataGroup-derived class!
-
DATA_ALLOW_PROXY¶ Whether to allow _all_ proxy types, i.e. classes derived from AbstractDataProxy
- Type
bool
-
DATA_EXPECTED_TYPES¶ Which types to allow. If None, all types are allowed.
- Type
tuple, None
-
DATA_UNEXPECTED_ACTION¶ The action to take when an unexpected type was supplied. Can be: raise, warn, ignore
- Type
str
-
DATA_EXPECTED_TYPES= None
-
DATA_ALLOW_PROXY= False
-
DATA_UNEXPECTED_ACTION= 'warn'
-