Skip to content

Commit 5cdd49b

Browse files
authored
gh-133196: Guard PEP 750 grammar with CHECK_VERSION (#133225)
1 parent feac343 commit 5cdd49b

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

Grammar/python.gram

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,12 @@ tstring_middle[expr_ty]:
971971
| tstring_replacement_field
972972
| t=TSTRING_MIDDLE { _PyPegen_constant_from_token(p, t) }
973973
tstring[expr_ty] (memo):
974-
| a=TSTRING_START b=tstring_middle* c=TSTRING_END { _PyPegen_template_str(p, a, (asdl_expr_seq*)b, c) }
974+
| a=TSTRING_START b=tstring_middle* c=TSTRING_END {
975+
CHECK_VERSION(
976+
expr_ty,
977+
14,
978+
"t-strings are",
979+
_PyPegen_template_str(p, a, (asdl_expr_seq*)b, c)) }
975980

976981
string[expr_ty]: s[Token*]=STRING { _PyPegen_constant_from_string(p, s) }
977982
strings[expr_ty] (memo): a[asdl_expr_seq*]=(fstring|string|tstring)+ { _PyPegen_concatenate_strings(p, a, EXTRA) }

Lib/test/test_ast/test_ast.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,12 @@ def test_assignment_expression_feature_version(self):
675675
with self.assertRaises(SyntaxError):
676676
ast.parse('(x := 0)', feature_version=(3, 7))
677677

678+
def test_pep750_tstring(self):
679+
code = 't""'
680+
ast.parse(code, feature_version=(3, 14))
681+
with self.assertRaises(SyntaxError):
682+
ast.parse(code, feature_version=(3, 13))
683+
678684
def test_pep758_except_without_parens(self):
679685
code = textwrap.dedent("""
680686
try:

Parser/parser.c

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)