Commit 28393828 authored by Victor Stinner's avatar Victor Stinner

Issue #14205: Fix test_dict.test_mutating_lookup()

parent 3774977d
...@@ -392,20 +392,27 @@ class DictTest(unittest.TestCase): ...@@ -392,20 +392,27 @@ class DictTest(unittest.TestCase):
class NastyKey: class NastyKey:
mutate_dict = None mutate_dict = None
def __init__(self, value):
self.value = value
def __hash__(self): def __hash__(self):
# hash collision! # hash collision!
return 1 return 1
def __eq__(self, other): def __eq__(self, other):
if self.mutate_dict: if NastyKey.mutate_dict:
self.mutate_dict[self] = 1 mydict, key = NastyKey.mutate_dict
return self == other NastyKey.mutate_dict = None
del mydict[key]
d = {} return self.value == other.value
d[NastyKey()] = 0
NastyKey.mutate_dict = d key1 = NastyKey(1)
with self.assertRaises(RuntimeError): key2 = NastyKey(2)
d[NastyKey()] = None d = {key1: 1}
NastyKey.mutate_dict = (d, key1)
with self.assertRaisesRegex(RuntimeError,
'dictionary changed size during lookup'):
d[key2] = 2
def test_repr(self): def test_repr(self):
d = {} d = {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment