From a762af74b2de734c44f7dc00358325d4485e2530 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Mon, 1 Jun 2015 22:59:08 -0600 Subject: Issue #24347: Set KeyError if PyDict_GetItemWithError returns NULL. --- Lib/test/test_collections.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'Lib/test/test_collections.py') diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index 3f02129c1d..931ac0ff0f 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -2037,6 +2037,24 @@ class CPythonOrderedDictTests(OrderedDictTests, unittest.TestCase): del od[colliding] self.assertEqual(list(od.items()), [(key, ...), ('after', ...)]) + def test_issue24347(self): + OrderedDict = self.module.OrderedDict + + class Key: + def __hash__(self): + return randrange(100000) + + od = OrderedDict() + for i in range(100): + key = Key() + od[key] = i + + # These should not crash. + with self.assertRaises(KeyError): + repr(od) + with self.assertRaises(KeyError): + od.copy() + class PurePythonGeneralMappingTests(mapping_tests.BasicTestMappingProtocol): -- cgit v1.2.1