]> 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:16:05 +0000 (03:16 -0800)
committerGitHub <noreply@github.com>
Wed, 16 Feb 2022 11:16:05 +0000 (03:16 -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/string_parser.c

index d0b1ade15137babaf2fac8284c8cc88637375828..0c255c2af22179bc50711a72ebc987c1a013fcb8 100644 (file)
@@ -1053,6 +1053,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 4c2043521c0cd33375491f3ba49558ef2faaa2c0..dac8dbb846471a27ae557b992fe5aee08e16a2d6 100644 (file)
@@ -666,12 +666,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. */
@@ -698,10 +698,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;