mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
protect against mutation of the dict during insertion (closes #24407)
This commit is contained in:
parent
dac3ab84c7
commit
a82f77fb00
3 changed files with 36 additions and 7 deletions
|
@ -906,6 +906,21 @@ class DictTest(unittest.TestCase):
|
|||
f.a = 'a'
|
||||
self.assertEqual(f.__dict__, {1:1, 'a':'a'})
|
||||
|
||||
def test_merge_and_mutate(self):
|
||||
class X:
|
||||
def __hash__(self):
|
||||
return 0
|
||||
|
||||
def __eq__(self, o):
|
||||
other.clear()
|
||||
return False
|
||||
|
||||
l = [(i,0) for i in range(1, 1337)]
|
||||
other = dict(l)
|
||||
other[X()] = 0
|
||||
d = {X(): 0, 1: 1}
|
||||
self.assertRaises(RuntimeError, d.update, other)
|
||||
|
||||
from test import mapping_tests
|
||||
|
||||
class GeneralMappingTests(mapping_tests.BasicTestMappingProtocol):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue