]> git.madduck.net Git - etc/vim.git/blob - tests/data/cases/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:

CI Test: Deprecating 'Healthcheck.all()' from Hypothesis in fuzz.py (#3945)
[etc/vim.git] / tests / data / cases / pattern_matching_extras.py
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 maybe, multiple:
34     case perhaps, 5:
35         pass
36     case perhaps, 6,:
37         pass
38
39
40 match more := (than, one), indeed,:
41     case _, (5, 6):
42         pass
43     case [[5], (6)], [7],:
44         pass
45     case _:
46         pass
47
48
49 match a, *b, c:
50     case [*_]:
51         assert "seq" == _
52     case {}:
53         assert "map" == b
54
55
56 match match(
57     case,
58     match(
59         match, case, match, looooooooooooooooooooooooooooooooooooong, match, case, match
60     ),
61     case,
62 ):
63     case case(
64         match=case,
65         case=re.match(
66             loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong
67         ),
68     ):
69         pass
70
71     case [a as match]:
72         pass
73
74     case case:
75         pass
76
77
78 match match:
79     case case:
80         pass
81
82
83 match a, *b(), c:
84     case d, *f, g:
85         pass
86
87
88 match something:
89     case {
90         "key": key as key_1,
91         "password": PASS.ONE | PASS.TWO | PASS.THREE as password,
92     }:
93         pass
94     case {"maybe": something(complicated as this) as that}:
95         pass
96
97
98 match something:
99     case 1 as a:
100         pass
101
102     case 2 as b, 3 as c:
103         pass
104
105     case 4 as d, (5 as e), (6 | 7 as g), *h:
106         pass
107
108
109 match bar1:
110     case Foo(aa=Callable() as aa, bb=int()):
111         print(bar1.aa, bar1.bb)
112     case _:
113         print("no match", "\n")
114
115
116 match bar1:
117     case Foo(
118         normal=x, perhaps=[list, {"x": d, "y": 1.0}] as y, otherwise=something, q=t as u
119     ):
120         pass