]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46762: Fix an assert failure in f-strings where > or < is the last character...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 16 Feb 2022 11:18:16 +0000 (03:18 -0800)
committerGitHub <noreply@github.com>
Wed, 16 Feb 2022 11:18:16 +0000 (03:18 -0800)
(cherry picked from commit ffd9f8ff84ed53c956b16d027f7d2926ea631051)

Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
Lib/test/test_fstring.py
Misc/NEWS.d/next/Core and Builtins/2022-02-15-20-26-46.bpo-46762.1H7vab.rst [new file with mode: 0644]
Parser/pegen/parse_string.c

index 92a4d22062f9847926034d9a5a3f3f81d8a44848..b62887f8f0099d2d32580bd37c6a4c70316e3c10 100644 (file)
@@ -1060,6 +1060,8 @@ x = (
                              "f'{{{'",
                              "f'{{}}{'",
                              "f'{'",
+                             "f'x{<'",  # See bpo-46762.
+                             "f'x{>'",
                              ])
 
         # But these are just normal strings.
diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-02-15-20-26-46.bpo-46762.1H7vab.rst b/Misc/NEWS.d/next/Core and Builtins/2022-02-15-20-26-46.bpo-46762.1H7vab.rst
new file mode 100644 (file)
index 0000000..cd53eb4
--- /dev/null
@@ -0,0 +1,2 @@
+Fix an assert failure in debug builds when a '<', '>', or '=' is the last
+character in an f-string that's missing a closing right brace.
index af350b340db68eceee3580de5551968b097197be..15a132b4e054472bdb6d48e72f6fb214e2896805 100644 (file)
@@ -668,12 +668,12 @@ fstring_find_expr(Parser *p, const char **str, const char *end, int raw, int rec
                     *str += 1;
                     continue;
                 }
-                /* Don't get out of the loop for these, if they're single
-                   chars (not part of 2-char tokens). If by themselves, they
-                   don't end an expression (unlike say '!'). */
-                if (ch == '>' || ch == '<') {
-                    continue;
-                }
+            }
+            /* Don't get out of the loop for these, if they're single
+               chars (not part of 2-char tokens). If by themselves, they
+               don't end an expression (unlike say '!'). */
+            if (ch == '>' || ch == '<') {
+                continue;
             }
 
             /* Normal way out of this loop. */
@@ -700,10 +700,10 @@ fstring_find_expr(Parser *p, const char **str, const char *end, int raw, int rec
         }
     }
     expr_end = *str;
-    /* If we leave this loop in a string or with mismatched parens, we
-       don't care. We'll get a syntax error when compiling the
-       expression. But, we can produce a better error message, so
-       let's just do that.*/
+    /* If we leave the above loop in a string or with mismatched parens, we
+       don't really care. We'll get a syntax error when compiling the
+       expression. But, we can produce a better error message, so let's just
+       do that.*/
     if (quote_char) {
         RAISE_SYNTAX_ERROR("f-string: unterminated string");
         goto error;