1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# gc-interval=200
# Test that hashing deeply nested containers raises RecursionError instead
# of crashing with a Rust stack overflow.
# === Deep tuple hash ===
x = (1,)
for _ in range(10000):
x = (x,)
try:
h = hash(x)
assert isinstance(h, int)
except RecursionError:
pass # acceptable if depth guard triggers
# === Deep frozenset hash ===
y = frozenset({1})
for _ in range(10000):
y = frozenset({y})
try:
h = hash(y)
assert isinstance(h, int)
except RecursionError:
pass # acceptable if depth guard triggers
# === Deep tuple as dict key (triggers hash) ===
z = (1,)
for _ in range(10000):
z = (z,)
d = {}
try:
d[z] = 'value'
except RecursionError:
pass # acceptable if depth guard triggers
# === Deep tuple as set element (triggers hash) ===
w = (1,)
for _ in range(10000):
w = (w,)
s = set()
try:
s.add(w)
except RecursionError:
pass # acceptable if depth guard triggers