mirror of
https://github.com/python/cpython.git
synced 2025-07-07 11:25:30 +00:00
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:
parent
ffb2a02f98
commit
fb9e292919
3 changed files with 5 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Differentiate between t-strings and f-strings in syntax error for newlines
|
||||
in format specifiers of single-quoted interpolated strings.
|
|
@ -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)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue