]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-129958: New syntax error in format spec applies to both f-strings and t-strings...
authorDylan <dylwil3@gmail.com>
Thu, 26 Jun 2025 13:02:50 +0000 (08:02 -0500)
committerGitHub <noreply@github.com>
Thu, 26 Jun 2025 13:02:50 +0000 (15:02 +0200)
Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Lib/test/test_tstring.py
Misc/NEWS.d/next/Core_and_Builtins/2025-06-24-06-41-47.gh-issue-129958.EaJuS0.rst [new file with mode: 0644]
Parser/lexer/lexer.c

index e72a1ea54176d5589464379ff149af4e14363309..aabae38556735b09b2ab3adef052ed6a4446db4c 100644 (file)
@@ -219,6 +219,7 @@ class TestTString(unittest.TestCase, TStringBaseCase):
             ("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 (file)
index 0000000..70b3e99
--- /dev/null
@@ -0,0 +1,2 @@
+Differentiate between t-strings and f-strings in syntax error for newlines
+in format specifiers of single-quoted interpolated strings.
index 4d10bccf0a53f2fb08ca01dee7c3c76921a37360..0a078dd594148cd20815d84ed72b909eaa61c6e7 100644 (file)
@@ -1421,7 +1421,8 @@ f_string_middle:
                     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)
                         )
                     );
                 }