gh-129958: New syntax error in format spec applies to both f-strings and t-strings (#135570)

Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
This commit is contained in:
Dylan 2025-06-26 08:02:50 -05:00 committed by GitHub
parent ffb2a02f98
commit fb9e292919
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 5 additions and 1 deletions

View file

@ -219,6 +219,7 @@ class TestTString(unittest.TestCase, TStringBaseCase):
("t'{lambda:1}'", "t-string: lambda expressions are not allowed "
"without parentheses"),
("t'{x:{;}}'", "t-string: expecting a valid expression after '{'"),
("t'{1:d\n}'", "t-string: newlines are not allowed in format specifiers")
):
with self.subTest(case), self.assertRaisesRegex(SyntaxError, err):
eval(case)

View file

@ -0,0 +1,2 @@
Differentiate between t-strings and f-strings in syntax error for newlines
in format specifiers of single-quoted interpolated strings.

View file

@ -1421,7 +1421,8 @@ f_string_middle:
return MAKE_TOKEN(
_PyTokenizer_syntaxerror(
tok,
"f-string: newlines are not allowed in format specifiers for single quoted f-strings"
"%c-string: newlines are not allowed in format specifiers for single quoted %c-strings",
TOK_GET_STRING_PREFIX(tok), TOK_GET_STRING_PREFIX(tok)
)
);
}