summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2010-12-31 23:16:17 (GMT)
committerRaymond Hettinger <python@rcn.com>2010-12-31 23:16:17 (GMT)
commita673b1fd0e6396e587a99ec9b2bec6b40132557a (patch)
tree08f806a0ce4cc5b7c2e4adefe60f6fcf19d3282e /Lib/test
parented13853e5dd22a85131b34707c6087677eec642a (diff)
downloadcpython-a673b1fd0e6396e587a99ec9b2bec6b40132557a.zip
cpython-a673b1fd0e6396e587a99ec9b2bec6b40132557a.tar.gz
cpython-a673b1fd0e6396e587a99ec9b2bec6b40132557a.tar.bz2
Fix OrderedDict.setdefault() to work for subclasses that define __missing__().
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_collections.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index 02b9dc3..32ce35b 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -976,6 +976,12 @@ class TestOrderedDict(unittest.TestCase):
# make sure 'x' is added to the end
self.assertEqual(list(od.items())[-1], ('x', 10))
+ # make sure setdefault still works when __missing__ is defined
+ class Missing(OrderedDict):
+ def __missing__(self, key):
+ return 0
+ self.assertEqual(Missing().setdefault(5, 9), 9)
+
def test_reinsert(self):
# Given insert a, insert b, delete a, re-insert a,
# verify that a is now later than b.