Re:A practical usage of ChainMap in Python
by andreareina on Tuesday September 25, 2018 @01:15AM
(#18063782)
Seems to be a strict design goal that the nothing below the top-most mapping is changed, which I appreciate.
>>> del inv['IMac']
deleting the key in the first mapping it appears. My guess is it is designed to ensure that updating a key will not update accidentally update a default mapping? This behavior could easily be prevented though by:
>>> from types import MappingProxyType >>> DEFAULTS = MappingProxyType(default_dict) >>> ChainMap(overrides, DEFAULTS)