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.
1 # flags: --minimum-version=3.10
13 def get_grammars(target_versions: Set[TargetVersion]) -> List[Grammar]:
14 if not target_versions:
15 # No target_version specified, so try all grammars.
18 pygram.python_grammar_no_print_statement_no_exec_statement_async_keywords,
20 pygram.python_grammar_no_print_statement_no_exec_statement,
21 # Python 2.7 with future print_function import
22 pygram.python_grammar_no_print_statement,
24 pygram.python_grammar,
33 if all(version.is_python2() for version in target_versions):
34 # Python 2-only code, so try Python 2 grammars.
36 # Python 2.7 with future print_function import
37 pygram.python_grammar_no_print_statement,
39 pygram.python_grammar,
44 with match() as match:
47 def test_patma_139(self):
52 self.assertIs(x, False)
53 self.assertEqual(y, 0)
56 # Python 3-compatible code, so only try Python 3 grammar.
58 if supports_feature(target_versions, Feature.PATTERN_MATCHING):
60 grammars.append(pygram.python_grammar_soft_keywords)
61 # If we have to parse both, try to parse async as a keyword first
62 if not supports_feature(
63 target_versions, Feature.ASYNC_IDENTIFIERS
64 ) and not supports_feature(target_versions, Feature.PATTERN_MATCHING):
67 pygram.python_grammar_no_print_statement_no_exec_statement_async_keywords
69 if not supports_feature(target_versions, Feature.ASYNC_KEYWORDS):
71 grammars.append(pygram.python_grammar_no_print_statement_no_exec_statement)
73 def test_patma_155(self):
79 self.assertEqual(x, 0)
80 self.assertIs(y, None)
84 case [y, case as x, z]:
87 # At least one of the above branches must have been taken, because every Python
88 # version has exactly one of the two 'ASYNC_*' flags
92 def lib2to3_parse(src_txt: str, target_versions: Iterable[TargetVersion] = ()) -> Node:
93 """Given a string with source, return the lib2to3 Node."""
94 if not src_txt.endswith("\n"):
97 grammars = get_grammars(set(target_versions))
102 with match() as match:
107 with match() as match: