gfw.common.collections#

Utility functions for collections.

Classes

DeepChainMap

A recursive version of ChainMap.

class DeepChainMap(*maps)[source]#

A recursive version of ChainMap.

Example

>>> base = {"a": {"x": 1}, "b": 2}
>>> override = {"a": {"y": 3}}
>>> dcm = DeepChainMap(override, base)
>>> dcm["a"]["x"]
1
>>> dcm["a"].to_dict()
{'x': 1, 'y': 3}
to_dict()[source]#

Returns a dictionary repr, taking care of any nested DeepChainMap instances.

Return type:

dict[K, V]

clear()#

Clear maps[0], leaving maps[1:] intact.

copy()#

New ChainMap or subclass with a new copy of maps[0] and refs to maps[1:]

classmethod fromkeys(iterable, *args)#

Create a ChainMap with a single dict created from the iterable.

get(k[, d]) D[k] if k in D, else d.  d defaults to None.#
items() a set-like object providing a view on D's items#
keys() a set-like object providing a view on D's keys#
new_child(m=None, **kwargs)#

New ChainMap with a new map followed by all previous maps. If no map is provided, an empty dict is used. Keyword arguments update the map or new empty dict.

property parents#

].

Type:

New ChainMap from maps[1

pop(key, *args)#

Remove key from maps[0] and return its value. Raise KeyError if key not in maps[0].

popitem()#

Remove and return an item pair from maps[0]. Raise KeyError is maps[0] is empty.

setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D#
update([E, ]**F) None.  Update D from mapping/iterable E and F.#

If E present and has a .keys() method, does: for k in E.keys(): D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

values() an object providing a view on D's values#