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

Allow top-level starred expression on match (#2659)
[etc/vim.git] / tests / data / 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 another:
27             ...
28         case func(match, case):
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         return "seq"
51     case {}:
52         return "map"