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.
12 def get_grammars(target_versions: Set[TargetVersion]) -> List[Grammar]:
13 if not target_versions:
14 # No target_version specified, so try all grammars.
17 pygram.python_grammar_no_print_statement_no_exec_statement_async_keywords,
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,
23 pygram.python_grammar,
32 if all(version.is_python2() for version in target_versions):
33 # Python 2-only code, so try Python 2 grammars.
35 # Python 2.7 with future print_function import
36 pygram.python_grammar_no_print_statement,
38 pygram.python_grammar,
43 with match() as match:
46 def test_patma_139(self):
51 self.assertIs(x, False)
52 self.assertEqual(y, 0)
55 # Python 3-compatible code, so only try Python 3 grammar.
57 if supports_feature(target_versions, Feature.PATTERN_MATCHING):
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):
66 pygram.python_grammar_no_print_statement_no_exec_statement_async_keywords
68 if not supports_feature(target_versions, Feature.ASYNC_KEYWORDS):
70 grammars.append(pygram.python_grammar_no_print_statement_no_exec_statement)
72 def test_patma_155(self):
78 self.assertEqual(x, 0)
79 self.assertIs(y, None)
83 case [y, case as x, z]:
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
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"):
96 grammars = get_grammars(set(target_versions))
101 with match() as match:
106 with match() as match: