Title: Add keyword argument support to ChainMap.new_child()
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.10
Status: open Resolution:
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: rhettinger
Priority: normal Keywords:

Created on 2021-02-17 19:48 by rhettinger, last changed 2021-02-17 19:48 by rhettinger.

Messages (1)
msg387186 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-02-17 19:48
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:
        return self.__class__(m, *self.maps)
Date User Action Args
2021-02-17 19:48:44rhettingercreate