mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Issue #24347: Set KeyError if PyDict_GetItemWithError returns NULL.
This commit is contained in:
parent
fa1b47cc5a
commit
a762af74b2
4 changed files with 69 additions and 15 deletions
|
@ -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):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue