gfw.common.collections.DeepChainMap#

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}

Methods

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:]

fromkeys

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

get

D.get(k[,d]) -> D[k] if k in D, else d.

items

D.items() -> a set-like object providing a view on D's items

keys

D.keys() -> a set-like object providing a view on D's keys

new_child

New ChainMap with a new map followed by all previous maps.

pop

Remove key from maps[0] and return its value.

popitem

Remove and return an item pair from maps[0].

setdefault

D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D

to_dict

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

update

D.update([E, ]**F) -> None.

values

D.values() -> an object providing a view on D's values

Attributes

parents

].

to_dict()[source]#

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

Return type:

dict[K, V]