This would it more convenient to extend chains for local contexts. Currently, we write:
local = parent.new_child(dict(foreground='white', background='cyan'))
Instead, it would be easier to write:
local = parent.new_child(foreground='white', background='cyan')
The new code would look like this:
def new_child(self, m=None, **kwargs):
'''New ChainMap with a new map followed by all previous maps.
If no map is provided, an empty dict is used.
Keyword arguments update the map or new empty dict:
'''
if m is None:
m = kwargs
elif kwargs:
m.update(kwargs)
return self.__class__(m, *self.maps)
|