Hacker News new | ask | show | jobs
by pmart123 2827 days 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)

1 comments

Seems to be a strict design goal that the nothing below the top-most mapping is changed, which I appreciate.