]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46762: Fix an assert failure in f-strings where > or < is the last character...
authorEric V. Smith <ericvsmith@users.noreply.github.com>
Wed, 16 Feb 2022 10:54:09 +0000 (05:54 -0500)
committerGitHub <noreply@github.com>
Wed, 16 Feb 2022 10:54:09 +0000 (05:54 -0500)
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 0b5e30ba2ca6a4cf5049a2f5f4132b8ba3823488..fae2a3648cf9f9004c86ac65b445df1d3ba8021a 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;