mirror of
https://github.com/python/cpython.git
synced 2025-08-09 11:29:45 +00:00
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 ffd9f8ff84
)
Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
This commit is contained in:
parent
c292118ef3
commit
a657bff349
3 changed files with 14 additions and 10 deletions
|
@ -1060,6 +1060,8 @@ x = (
|
||||||
"f'{{{'",
|
"f'{{{'",
|
||||||
"f'{{}}{'",
|
"f'{{}}{'",
|
||||||
"f'{'",
|
"f'{'",
|
||||||
|
"f'x{<'", # See bpo-46762.
|
||||||
|
"f'x{>'",
|
||||||
])
|
])
|
||||||
|
|
||||||
# But these are just normal strings.
|
# But these are just normal strings.
|
||||||
|
|
|
@ -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.
|
|
@ -668,12 +668,12 @@ fstring_find_expr(Parser *p, const char **str, const char *end, int raw, int rec
|
||||||
*str += 1;
|
*str += 1;
|
||||||
continue;
|
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 get out of the loop for these, if they're single
|
||||||
don't end an expression (unlike say '!'). */
|
chars (not part of 2-char tokens). If by themselves, they
|
||||||
if (ch == '>' || ch == '<') {
|
don't end an expression (unlike say '!'). */
|
||||||
continue;
|
if (ch == '>' || ch == '<') {
|
||||||
}
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Normal way out of this loop. */
|
/* 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;
|
expr_end = *str;
|
||||||
/* If we leave this loop in a string or with mismatched parens, we
|
/* If we leave the above loop in a string or with mismatched parens, we
|
||||||
don't care. We'll get a syntax error when compiling the
|
don't really care. We'll get a syntax error when compiling the
|
||||||
expression. But, we can produce a better error message, so
|
expression. But, we can produce a better error message, so let's just
|
||||||
let's just do that.*/
|
do that.*/
|
||||||
if (quote_char) {
|
if (quote_char) {
|
||||||
RAISE_SYNTAX_ERROR("f-string: unterminated string");
|
RAISE_SYNTAX_ERROR("f-string: unterminated string");
|
||||||
goto error;
|
goto error;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue