News for hackers. Stuff that matters.
Re:A practical usage of ChainMap in Python by pmart123 on Monday September 24, 2018 @01:27PM (#18059550)
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)

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.