Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Lib/test/test_tstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def test_syntax_errors(self):
("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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Differentiate between t-strings and f-strings in syntax error for newlines
in format specifiers of single-quoted interpolated strings.
3 changes: 2 additions & 1 deletion Parser/lexer/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,8 @@ tok_get_fstring_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct
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)
)
);
}
Expand Down
Loading