summaryrefslogtreecommitdiffstats
path: root/Lib/collections
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2011-02-23 07:56:53 (GMT)
committerRaymond Hettinger <python@rcn.com>2011-02-23 07:56:53 (GMT)
commit499e19340ec12aa49f0117b6af90ec4cab853960 (patch)
treee7744a4750aea0a78d1b6fd3385142e8edb3bd05 /Lib/collections
parent08f5cf51dcd7d065d791c3bad1ae6a9e5f874d59 (diff)
downloadcpython-499e19340ec12aa49f0117b6af90ec4cab853960.zip
cpython-499e19340ec12aa49f0117b6af90ec4cab853960.tar.gz
cpython-499e19340ec12aa49f0117b6af90ec4cab853960.tar.bz2
Add tests for the _ChainMap helper class.
Diffstat (limited to 'Lib/collections')
-rw-r--r--Lib/collections/__init__.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py
index 89cf2ed..11a2993 100644
--- a/Lib/collections/__init__.py
+++ b/Lib/collections/__init__.py
@@ -695,6 +695,15 @@ 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)
+
+ @property
+ def parents(self): # like Django's Context.pop()
+ 'New ChainMap from maps[1:].'
+ return self.__class__(*self.maps[1:])
+
def __setitem__(self, key, value):
self.maps[0][key] = value