From a82f77fb00ca3bd3eb27a6a5d77a19eadcf0ba31 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sat, 4 Jul 2015 19:55:16 -0500 Subject: protect against mutation of the dict during insertion (closes #24407) --- Lib/test/test_dict.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'Lib/test/test_dict.py') diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py index a38895945e..bd3040a7f6 100644 --- a/Lib/test/test_dict.py +++ b/Lib/test/test_dict.py @@ -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): -- cgit v1.2.1