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

Bump actions/checkout from 3 to 4 (#3883)
[etc/vim.git] / tests / data / py_310 / pattern_matching_generic.py
1 re.match()
2 match = a
3 with match() as match:
4     match = f"{match}"
5
6 re.match()
7 match = a
8 with match() as match:
9     match = f"{match}"
10
11
12 def get_grammars(target_versions: Set[TargetVersion]) -> List[Grammar]:
13     if not target_versions:
14         # No target_version specified, so try all grammars.
15         return [
16             # Python 3.7+
17             pygram.python_grammar_no_print_statement_no_exec_statement_async_keywords,
18             # Python 3.0-3.6
19             pygram.python_grammar_no_print_statement_no_exec_statement,
20             # Python 2.7 with future print_function import
21             pygram.python_grammar_no_print_statement,
22             # Python 2.7
23             pygram.python_grammar,
24         ]
25
26     match match:
27         case case:
28             match match:
29                 case case:
30                     pass
31
32     if all(version.is_python2() for version in target_versions):
33         # Python 2-only code, so try Python 2 grammars.
34         return [
35             # Python 2.7 with future print_function import
36             pygram.python_grammar_no_print_statement,
37             # Python 2.7
38             pygram.python_grammar,
39         ]
40
41     re.match()
42     match = a
43     with match() as match:
44         match = f"{match}"
45
46     def test_patma_139(self):
47         x = False
48         match x:
49             case bool(z):
50                 y = 0
51         self.assertIs(x, False)
52         self.assertEqual(y, 0)
53         self.assertIs(z, x)
54
55     # Python 3-compatible code, so only try Python 3 grammar.
56     grammars = []
57     if supports_feature(target_versions, Feature.PATTERN_MATCHING):
58         # Python 3.10+
59         grammars.append(pygram.python_grammar_soft_keywords)
60     # If we have to parse both, try to parse async as a keyword first
61     if not supports_feature(
62         target_versions, Feature.ASYNC_IDENTIFIERS
63     ) and not supports_feature(target_versions, Feature.PATTERN_MATCHING):
64         # Python 3.7-3.9
65         grammars.append(
66             pygram.python_grammar_no_print_statement_no_exec_statement_async_keywords
67         )
68     if not supports_feature(target_versions, Feature.ASYNC_KEYWORDS):
69         # Python 3.0-3.6
70         grammars.append(pygram.python_grammar_no_print_statement_no_exec_statement)
71
72     def test_patma_155(self):
73         x = 0
74         y = None
75         match x:
76             case 1e1000:
77                 y = 0
78         self.assertEqual(x, 0)
79         self.assertIs(y, None)
80
81         x = range(3)
82         match x:
83             case [y, case as x, z]:
84                 w = 0
85
86     # At least one of the above branches must have been taken, because every Python
87     # version has exactly one of the two 'ASYNC_*' flags
88     return grammars
89
90
91 def lib2to3_parse(src_txt: str, target_versions: Iterable[TargetVersion] = ()) -> Node:
92     """Given a string with source, return the lib2to3 Node."""
93     if not src_txt.endswith("\n"):
94         src_txt += "\n"
95
96     grammars = get_grammars(set(target_versions))
97
98
99 re.match()
100 match = a
101 with match() as match:
102     match = f"{match}"
103
104 re.match()
105 match = a
106 with match() as match:
107     match = f"{match}"