Forwarding dictionary

Special dictioanry class to forward attributes indefinitely.

class pylada.jobfolder.forwarding_dict.ForwardingDict(ordered=True, readonly=None, naked_end=None, only_existing=None, _attr_list=None, dictionary=None)[source]

Bases: _abcoll.MutableMapping

An ordered dictionary which forwards attributes.

Overloads the . operator to access items for which the particular attribute exists. The return is another instance of ForwaringDict. In this manner, attributes can chained with calls to the``.`` operator. The values of forwarded attributes can also be changed.

__init__(ordered=True, readonly=None, naked_end=None, only_existing=None, _attr_list=None, dictionary=None)[source]

Initializes a ForwardingDict instance.

Parameters:
  • readonly (bool) – Whether or not the items in the dictionary can be modified. If None, defaults to pylada.jobparams_read_only.
  • naked_end (bool) – When only one item exists with the last forwarded attribute, whether it should be returned itself, or whether a ForwardingDict should still be returned. Former is easier when examining objects interactively, latter is better in scripts. If None, defaults to pylada.jobparams_naked_end.
  • only_existing (bool) – When setting attributes, whether to allow creation of new attributes for items which do not posses it. If None, defaults to pylada.jobparams_only_existing
  • _attr_list – A list of strings making up the attributes to unroll. Private.
  • dictionary (dict) – Initializes items from items in dictionary.
readonly

Whether items can be modified in parallel using attribute syntax.

naked_end

Whether last item is returned as is or wrapped in ForwardingDict.

only_existing

Whether attributes can be added or only modified.

dictionary

The dictionary for which to unroll attributes.

root[source]

Returns a ForwardingDict with root grandparent.

parent[source]

Returns a ForwardingDict with parent items of self, eg unrolled once.

keys()[source]
copy(append=None, dict=None, **kwargs)[source]

Returns a shallow copy of this object.

:param str append : str or None
Append value to a deepcopy of a list of attributes. Ignored if None.
:param kwargs : dict
Any other attribute to set in the ForwardingDict instance. Note that only attributes of the ForwardingDict instance are set/modified. This is not propagated to the object the dict holds.
__getitem__(key)[source]
__setitem__(key, value)[source]

Add/modify item to dictionary.

Items can be truly added only to root dictionary.

__getattr__(name)[source]

Returns a Forwarding dict with next requested attribute.

__setattr__(name, value)[source]

Forwards attribute setting.

Previous topic

Extract base classes

Next topic

Process Module

This Page