https://github.com/python/cpython/commit/204545317144b90942d0a7265e1433a831cfeb5d
commit: 204545317144b90942d0a7265e1433a831cfeb5d
branch: 3.14
author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com>
committer: lysnikolaou <lisandros...@gmail.com>
date: 2025-06-26T18:40:09+02:00
summary:

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

(cherry picked from commit fb9e292919d82326acea456aa071c9af6aff5626)

Co-authored-by: Dylan <dylw...@gmail.com>
Co-authored-by: Tomas R. <tomas.ro...@gmail.com>
Co-authored-by: Lysandros Nikolaou <lisandros...@gmail.com>

files:
A 
Misc/NEWS.d/next/Core_and_Builtins/2025-06-24-06-41-47.gh-issue-129958.EaJuS0.rst
M Lib/test/test_tstring.py
M Parser/lexer/lexer.c

diff --git a/Lib/test/test_tstring.py b/Lib/test/test_tstring.py
index e72a1ea54176d5..aabae38556735b 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)
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.
diff --git a/Parser/lexer/lexer.c b/Parser/lexer/lexer.c
index 4d10bccf0a53f2..0a078dd594148c 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)
                         )
                     );
                 }

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: arch...@mail-archive.com

Reply via email to