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. (#31365)

This commit is contained in:
Eric V. Smith 2022-02-16 05:54:09 -05:00 committed by GitHub
parent e59309b9d0
commit ffd9f8ff84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 10 deletions

View File

@ -1053,6 +1053,8 @@ x = (
"f'{{{'",
"f'{{}}{'",
"f'{'",
"f'x{<'", # See bpo-46762.
"f'x{>'",
])
# But these are just normal strings.

View File

@ -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.

View File

@ -666,13 +666,13 @@ 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;
}
}
/* Normal way out of this loop. */
break;
@ -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;