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
# PMAT-1059: MULTIPLE `except` clauses on a statement-form try —
# `try: B except E1: H1 except E2: H2 except: H3`. The Err arm of the
# catch_unwind emits an ordered if/else-if chain over the handlers (the first
# matching type wins, source order); a catch-all (`except:` / `except
# Exception:`, empty types — Python-required last) is the final `else`, else
# the chain ends in resume_unwind (an unmatched exception PROPAGATES, not
# swallowed). Extends Stmt::TryCatch additively (extra_handlers, serde-default
# so single-except IR is unchanged). Verified vs CPython (val/key/other/key/idx).
def raise_kind(kind: int) -> int:
if kind == 1:
raise ValueError("v")
if kind == 2:
raise KeyError("k")
return 1 // 0
def classify(kind: int) -> str:
result: str = "none"
try:
raise_kind(kind)
except KeyError:
result = "key"
except ValueError:
result = "val"
except:
result = "other"
return result
def ordered_first_wins() -> str:
d: dict[str, int] = {}
result: str = "?"
try:
_ = d["missing"]
except KeyError:
result = "key"
except Exception:
result = "exc"
return result
def tuple_then_single() -> str:
result: str = "?"
try:
raise IndexError("i")
except (KeyError, ValueError):
result = "kv"
except IndexError:
result = "idx"
return result