]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-113703: Correctly identify incomplete f-strings in the codeop module (GH...
authorPablo Galindo Salgado <Pablogsal@gmail.com>
Fri, 5 Jan 2024 13:23:40 +0000 (13:23 +0000)
committerGitHub <noreply@github.com>
Fri, 5 Jan 2024 13:23:40 +0000 (13:23 +0000)
(cherry picked from commit 3003fbbf00422bce6e327646063e97470afa9091)

Lib/test/test_codeop.py
Misc/NEWS.d/next/Core and Builtins/2024-01-04-17-15-30.gh-issue-113703.Zsk0pY.rst [new file with mode: 0644]
Parser/tokenizer.c

index 2abb6c6d935b7e7653543289c6e704047eb9bc12..787bd1b6a79e20b8df91ab36a425ff1eb96eb591 100644 (file)
@@ -223,6 +223,9 @@ class CodeopTests(unittest.TestCase):
         ai("(x for x in")
         ai("(x for x in (")
 
+        ai('a = f"""')
+        ai('a = \\')
+
     def test_invalid(self):
         ai = self.assertInvalid
         ai("a b")
diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-01-04-17-15-30.gh-issue-113703.Zsk0pY.rst b/Misc/NEWS.d/next/Core and Builtins/2024-01-04-17-15-30.gh-issue-113703.Zsk0pY.rst
new file mode 100644 (file)
index 0000000..5db93e3
--- /dev/null
@@ -0,0 +1,2 @@
+Fix a regression in the :mod:`codeop` module that was causing it to incorrectly
+identify incomplete f-strings. Patch by Pablo Galindo
index d2f967d35ac4b3716418b145c72829615eec65c5..04ba04428fef6256e834378ac9095f83e3289f1a 100644 (file)
@@ -2851,9 +2851,13 @@ f_string_middle:
             tok->lineno = the_current_tok->f_string_line_start;
 
             if (current_tok->f_string_quote_size == 3) {
-                return MAKE_TOKEN(syntaxerror(tok,
-                                    "unterminated triple-quoted f-string literal"
-                                    " (detected at line %d)", start));
+                syntaxerror(tok,
+                            "unterminated triple-quoted f-string literal"
+                            " (detected at line %d)", start);
+                if (c != '\n') {
+                    tok->done = E_EOFS;
+                }
+                return MAKE_TOKEN(ERRORTOKEN);
             }
             else {
                 return MAKE_TOKEN(syntaxerror(tok,