diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2012-03-06 00:03:13 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2012-03-06 00:03:13 (GMT) |
commit | 198b291df7ae66d507849d92ddb6588a630fb71c (patch) | |
tree | 9f168ad6e96b6bc9c372dedddafe1f07973c0999 /Lib/test/test_dict.py | |
parent | b2c7cca0cfda2836ff4ef222bb23ff07a79600fd (diff) | |
download | cpython-198b291df7ae66d507849d92ddb6588a630fb71c.zip cpython-198b291df7ae66d507849d92ddb6588a630fb71c.tar.gz cpython-198b291df7ae66d507849d92ddb6588a630fb71c.tar.bz2 |
Close #14205: dict lookup raises a RuntimeError if the dict is modified during
a lookup.
"if you want to make a sandbox on top of CPython, you have to fix segfaults"
so let's fix segfaults!
Diffstat (limited to 'Lib/test/test_dict.py')
-rw-r--r-- | Lib/test/test_dict.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py index d2740a3..15db51d 100644 --- a/Lib/test/test_dict.py +++ b/Lib/test/test_dict.py @@ -379,7 +379,7 @@ class DictTest(unittest.TestCase): x.fail = True self.assertRaises(Exc, d.pop, x) - def test_mutatingiteration(self): + def test_mutating_iteration(self): # changing dict size during iteration d = {} d[1] = 1 @@ -387,6 +387,26 @@ class DictTest(unittest.TestCase): for i in d: d[i+1] = 1 + def test_mutating_lookup(self): + # changing dict during a lookup + class NastyKey: + mutate_dict = None + + def __hash__(self): + # hash collision! + return 1 + + def __eq__(self, other): + if self.mutate_dict: + self.mutate_dict[self] = 1 + return self == other + + d = {} + d[NastyKey()] = 0 + NastyKey.mutate_dict = d + with self.assertRaises(RuntimeError): + d[NastyKey()] = None + def test_repr(self): d = {} self.assertEqual(repr(d), '{}') |