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
49
50
51
52
53
54
55
56
57
58
# PMAT-1070: `finally:` on a statement-form try/except — runs in EVERY exit
# path (clean body, matched handler, handler-raised, unmatched-propagate).
# Emitted by wrapping the whole try/except in an OUTER catch_unwind: run F
# after, then re-propagate if the inner still panicked (so F runs even when a
# handler itself raises, and BEFORE the exception reaches an enclosing try).
# Works with single + multiple except. Deferred: finally-ONLY (no except —
# needs a no-catch encoding distinct from `except: pass`), and `else`.
# Differentially verified vs CPython (tf/tef/kF/1).
def clean_path() -> str:
log: str = ""
try:
log = log + "t"
except ValueError:
log = log + "e"
finally:
log = log + "f"
return log
def caught_path() -> str:
log: str = ""
try:
log = log + "t"
raise ValueError("v")
except ValueError:
log = log + "e"
finally:
log = log + "f"
return log
def multi_except_finally() -> str:
log: str = ""
try:
raise KeyError("k")
except ValueError:
log = "v"
except KeyError:
log = "k"
finally:
log = log + "F"
return log
def finally_runs_before_propagate() -> int:
trace: list[int] = []
result: int = -1
try:
try:
raise IndexError("i")
except ValueError:
trace.append(1)
finally:
trace.append(2)
except IndexError:
result = len(trace)
return result