]> git.madduck.net Git - etc/vim.git/blob - tests/data/py_310/pattern_matching_extras.py

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

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