From 3f2df416f7b72a14f2a4ad459c78cc0f2b8b6897 Mon Sep 17 00:00:00 2001 From: dylwil3 Date: Mon, 16 Jun 2025 10:31:57 -0500 Subject: [PATCH 1/5] use token prefix in syntax error message --- Parser/lexer/lexer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Parser/lexer/lexer.c b/Parser/lexer/lexer.c index 4d10bccf0a53f2..9c02d4531aeeb8 100644 --- a/Parser/lexer/lexer.c +++ b/Parser/lexer/lexer.c @@ -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) ) ); } From 256da628051052044c1e540d254c2bc430e2eec4 Mon Sep 17 00:00:00 2001 From: Dylan Date: Tue, 24 Jun 2025 06:33:07 -0500 Subject: [PATCH 2/5] whitespace Co-authored-by: Tomas R. --- Parser/lexer/lexer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Parser/lexer/lexer.c b/Parser/lexer/lexer.c index 9c02d4531aeeb8..0a078dd594148c 100644 --- a/Parser/lexer/lexer.c +++ b/Parser/lexer/lexer.c @@ -1422,7 +1422,7 @@ tok_get_fstring_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct _PyTokenizer_syntaxerror( tok, "%c-string: newlines are not allowed in format specifiers for single quoted %c-strings", - TOK_GET_STRING_PREFIX(tok),TOK_GET_STRING_PREFIX(tok) + TOK_GET_STRING_PREFIX(tok), TOK_GET_STRING_PREFIX(tok) ) ); } From 7fc6def234c3646889d81ab4114cc0dbf7de1d90 Mon Sep 17 00:00:00 2001 From: dylwil3 Date: Tue, 24 Jun 2025 06:42:08 -0500 Subject: [PATCH 3/5] add news entry --- .../2025-06-24-06-41-47.gh-issue-129958.EaJuS0.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2025-06-24-06-41-47.gh-issue-129958.EaJuS0.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-06-24-06-41-47.gh-issue-129958.EaJuS0.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-06-24-06-41-47.gh-issue-129958.EaJuS0.rst new file mode 100644 index 00000000000000..70b3e99425df14 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-06-24-06-41-47.gh-issue-129958.EaJuS0.rst @@ -0,0 +1,2 @@ +Differentiate between t-strings and f-strings in syntax error for newlines +in format specifiers of single-quoted interpolated strings. From 824e1ca5ae12e9a237658ebc0a3d8d6dc4450903 Mon Sep 17 00:00:00 2001 From: dylwil3 Date: Tue, 24 Jun 2025 06:46:33 -0500 Subject: [PATCH 4/5] add test for new message on t-strings --- Lib/test/test_tstring.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_tstring.py b/Lib/test/test_tstring.py index e72a1ea54176d5..d01b9cc1b10e5f 100644 --- a/Lib/test/test_tstring.py +++ b/Lib/test/test_tstring.py @@ -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) From 68f8f1f0e1ee2f0c0f2703cea252ef69a0b5b60e Mon Sep 17 00:00:00 2001 From: Dylan Date: Wed, 25 Jun 2025 19:29:30 -0500 Subject: [PATCH 5/5] nit Co-authored-by: Lysandros Nikolaou --- Lib/test/test_tstring.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_tstring.py b/Lib/test/test_tstring.py index d01b9cc1b10e5f..aabae38556735b 100644 --- a/Lib/test/test_tstring.py +++ b/Lib/test/test_tstring.py @@ -219,7 +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") + ("t'{1:d\n}'", "t-string: newlines are not allowed in format specifiers") ): with self.subTest(case), self.assertRaisesRegex(SyntaxError, err): eval(case)