FWIW I find the current behavior preferable. In fact in all cases I use ChainMap the first mapping is always an empty dictionary, because I specifically don't want to mutate the others.
>>> 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)
However, it appears that the “locals, globals, builtins” lookup was the design constraint this was intended for, and the core of Python seems to prefer new classes over compact functionality. For example look at OrderedDict not just being an “ordered=“ keyword only parameter (ordered) on dict.
But yes, I'm interested in the call signature you propose such that it's possible to tell whether
dict(ordered=True)
Means `OrderedDict([])` or `{'ordered': True}`. chain_map.maps[0][key] = value
I wouldn't expect this to work because `0` is a valid key. It's not safe to assume that an integer lookup is an index.
Does anyone know why this decision was made?
[0]: https://docs.python.org/3.7/library/collections.html#chainma...