Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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