diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2013-01-11 23:39:53 +0000 |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2013-01-11 23:39:53 +0000 |
commit | 34a2132a99b9f54c306d1d249d19303bdf33769f (patch) | |
tree | 32a57c8a022daf211414d761ce685a9028bd7485 /Lib/collections | |
parent | 1f0b1930a7281407969f7c70eba70a9fc8d31a04 (diff) | |
download | cpython-34a2132a99b9f54c306d1d249d19303bdf33769f.tar.gz |
Closes #16613: Added optional mapping argument to ChainMap.new_child.
Diffstat (limited to 'Lib/collections')
-rw-r--r-- | Lib/collections/__init__.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index 53083e4bd6..0612e1f610 100644 --- a/Lib/collections/__init__.py +++ b/Lib/collections/__init__.py @@ -821,9 +821,14 @@ class ChainMap(MutableMapping): __copy__ = copy - def new_child(self): # like Django's Context.push() - 'New ChainMap with a new dict followed by all previous maps.' - return self.__class__({}, *self.maps) + def new_child(self, m=None): # like Django's Context.push() + ''' + New ChainMap with a new map followed by all previous maps. If no + map is provided, an empty dict is used. + ''' + if m is None: + m = {} + return self.__class__(m, *self.maps) @property def parents(self): # like Django's Context.pop() |