Debian Codegraph @

tests/data/cases/pattern_matching_extras.py

raw
1 # flags: --minimum-version=3.10
2 import match
3
4 match something:
5 case [a as b]:
6 print(b)
7 case [a as b, c, d, e as f]:
8 print(f)
9 case Point(a as b):
10 print(b)
11 case Point(int() as x, int() as y):
12 print(x, y)
13
14
15 match = 1
16 case: int = re.match(something)
17
18 match re.match(case):
19 case type("match", match):
20 pass
21 case match:
22 pass
23
24
25 def func(match: case, case: match) -> case:
26 match Something():
27 case func(match, case):
28 ...
29 case another:
30 ...
31
32
33 match a, *b, c:
34 case [*_]:
35 assert "seq" == _
36 case {}:
37 assert "map" == b
38
39
40 match match(
41 case,
42 match(
43 match, case, match, looooooooooooooooooooooooooooooooooooong, match, case, match
44 ),
45 case,
46 ):
47 case case(
48 match=case,
49 case=re.match(
50 loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong
51 ),
52 ):
53 pass
54 case [a as match]:
55 pass
56 case case:
57 pass
58 case something:
59 pass
60
61
62 match match:
63 case case:
64 pass
65
66
67 match a, *b(), c:
68 case d, *f, g:
69 pass
70
71
72 match something:
73 case {
74 "key": key as key_1,
75 "password": PASS.ONE | PASS.TWO | PASS.THREE as password,
76 }:
77 pass
78 case {"maybe": something(complicated as this) as that}:
79 pass
80
81
82 match something:
83 case 1 as a:
84 pass
85 case 2 as b, 3 as c:
86 pass
87 case 4 as d, (5 as e), (6 | 7 as g), *h:
88 pass
89
90
91 match bar1:
92 case Foo(aa=Callable() as aa, bb=int()):
93 print(bar1.aa, bar1.bb)
94 case _:
95 print("no match", "\n")
96
97
98 match bar1:
99 case Foo(
100 normal=x, perhaps=[list, {"x": d, "y": 1.0}] as y, otherwise=something, q=t as u
101 ):
102 pass