ยปCore Development>Code coverage>Lib/test/crashers/nasty_eq_vs_dict.py

Python code coverage for Lib/test/crashers/nasty_eq_vs_dict.py

#countcontent
1n/a# from http://mail.python.org/pipermail/python-dev/2001-June/015239.html
2n/a
3n/a# if you keep changing a dictionary while looking up a key, you can
4n/a# provoke an infinite recursion in C
5n/a
6n/a# At the time neither Tim nor Michael could be bothered to think of a
7n/a# way to fix it.
8n/a
9n/aclass Yuck:
10n/a def __init__(self):
11n/a self.i = 0
12n/a
13n/a def make_dangerous(self):
14n/a self.i = 1
15n/a
16n/a def __hash__(self):
17n/a # direct to slot 4 in table of size 8; slot 12 when size 16
18n/a return 4 + 8
19n/a
20n/a def __eq__(self, other):
21n/a if self.i == 0:
22n/a # leave dict alone
23n/a pass
24n/a elif self.i == 1:
25n/a # fiddle to 16 slots
26n/a self.__fill_dict(6)
27n/a self.i = 2
28n/a else:
29n/a # fiddle to 8 slots
30n/a self.__fill_dict(4)
31n/a self.i = 1
32n/a
33n/a return 1
34n/a
35n/a def __fill_dict(self, n):
36n/a self.i = 0
37n/a dict.clear()
38n/a for i in range(n):
39n/a dict[i] = i
40n/a dict[self] = "OK!"
41n/a
42n/ay = Yuck()
43n/adict = {y: "OK!"}
44n/a
45n/az = Yuck()
46n/ay.make_dangerous()
47n/aprint(dict[z])