[New-bugs-announce] [issue43245] Add keyword argument support to ChainMap.new_child()

Raymond Hettinger report at bugs.python.org
Wed Feb 17 14:48:44 EST 2021


New submission from Raymond Hettinger <raymond.hettinger at gmail.com>:

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)

----------
assignee: rhettinger
components: Library (Lib)
messages: 387186
nosy: rhettinger
priority: normal
severity: normal
status: open
title: Add keyword argument support to ChainMap.new_child()
type: behavior
versions: Python 3.10

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43245>
_______________________________________


More information about the New-bugs-announce mailing list