[Python-checkins] bpo-46762: Fix an assert failure in f-strings where > or < is the last character if the f-string is missing a trailing right brace. (GH-31365)
miss-islington
webhook-mailer at python.org
Wed Feb 16 06:18:22 EST 2022
https://github.com/python/cpython/commit/a657bff34945e40be24cd75d02560a93b7623cf5
commit: a657bff34945e40be24cd75d02560a93b7623cf5
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-02-16T03:18:16-08:00
summary:
bpo-46762: Fix an assert failure in f-strings where > or < is the last character if the f-string is missing a trailing right brace. (GH-31365)
(cherry picked from commit ffd9f8ff84ed53c956b16d027f7d2926ea631051)
Co-authored-by: Eric V. Smith <ericvsmith at users.noreply.github.com>
files:
A Misc/NEWS.d/next/Core and Builtins/2022-02-15-20-26-46.bpo-46762.1H7vab.rst
M Lib/test/test_fstring.py
M Parser/pegen/parse_string.c
diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py
index 92a4d22062f98..b62887f8f0099 100644
--- a/Lib/test/test_fstring.py
+++ b/Lib/test/test_fstring.py
@@ -1060,6 +1060,8 @@ def test_mismatched_braces(self):
"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
index 0000000000000..cd53eb4ffaddd
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2022-02-15-20-26-46.bpo-46762.1H7vab.rst
@@ -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.
diff --git a/Parser/pegen/parse_string.c b/Parser/pegen/parse_string.c
index af350b340db68..15a132b4e0544 100644
--- a/Parser/pegen/parse_string.c
+++ b/Parser/pegen/parse_string.c
@@ -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;
More information about the Python-checkins
mailing list