4 ms·
hmm. That is not what I would have expected. I would have thought it would update the value of the first map with the key "iMac", otherwise, add the key to the
by pmart123 8y ago
hmm. That is not what I would have expected. I would have thought it would update the value of the first map with the key "iMac", otherwise, add the key to the top level. The same would go for:
>>> 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)
- andreareina 8y agoSeems to be a strict design goal that the nothing below the top-most mapping is changed, which I appreciate.