8000 gh-129958: New syntax error in format spec applies to both f-strings … · python/cpython@fb9e292 · GitHub
[go: up one dir, main page]

Skip to content

Commit fb9e292

Browse files
dylwil3tomasr8lysnikolaou
authored
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>
1 parent ffb2a02 commit fb9e292

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

Lib/test/test_tstring.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ def test_syntax_errors(self):
219219
("t'{lambda:1}'", "t-string: lambda expressions are not allowed "
220220
"without parentheses"),
221221
("t'{x:{;}}'", "t-string: expecting a valid expression after '{'"),
222+
("t'{1:d\n}'", "t-string: newlines are not allowed in format specifiers")
222223
):
223224
with self.subTest(case), self.assertRaisesRegex(SyntaxError, err):
224225
eval(case)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Differentiate between t-strings and f-strings in syntax error for newlines
2+
in format specifiers of single-quoted interpolated strings.

Parser/lexer/lexer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,8 @@ tok_get_fstring_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct
14211421
return MAKE_TOKEN(
14221422
_PyTokenizer_syntaxerror(
14231423
tok,
1424-
"f-string: newlines are not allowed in format specifiers for single quoted f-strings"
1424+
"%c-string: newlines are not allowed in format specifiers for single quoted %c-strings",
1425+
TOK_GET_STRING_PREFIX(tok), TOK_GET_STRING_PREFIX(tok)
14251426
)
14261427
);
14271428
}

0 commit comments

Comments
 (0)
0