mirror of https://github.com/python/cpython
gh-122026: Fix identification of mismatched parentheses inside f-strings (#122028)
This commit is contained in:
parent
186b4d8ea2
commit
2009e25e26
|
@ -896,6 +896,7 @@ x = (
|
||||||
"f'{:2}'",
|
"f'{:2}'",
|
||||||
"f'''{\t\f\r\n:a}'''",
|
"f'''{\t\f\r\n:a}'''",
|
||||||
"f'{:'",
|
"f'{:'",
|
||||||
|
"F'{[F'{:'}[F'{:'}]]]",
|
||||||
])
|
])
|
||||||
|
|
||||||
self.assertAllRaise(SyntaxError,
|
self.assertAllRaise(SyntaxError,
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix a bug that caused the tokenizer to not correctly identify mismatched
|
||||||
|
parentheses inside f-strings in some situations. Patch by Pablo Galindo
|
|
@ -1238,6 +1238,9 @@ tok_get_normal_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct t
|
||||||
|
|
||||||
if (INSIDE_FSTRING(tok)) {
|
if (INSIDE_FSTRING(tok)) {
|
||||||
current_tok->curly_bracket_depth--;
|
current_tok->curly_bracket_depth--;
|
||||||
|
if (current_tok->curly_bracket_depth < 0) {
|
||||||
|
return MAKE_TOKEN(_PyTokenizer_syntaxerror(tok, "f-string: unmatched '%c'", c));
|
||||||
|
}
|
||||||
if (c == '}' && current_tok->curly_bracket_depth == current_tok->curly_bracket_expr_start_depth) {
|
if (c == '}' && current_tok->curly_bracket_depth == current_tok->curly_bracket_expr_start_depth) {
|
||||||
current_tok->curly_bracket_expr_start_depth--;
|
current_tok->curly_bracket_expr_start_depth--;
|
||||||
current_tok->kind = TOK_FSTRING_MODE;
|
current_tok->kind = TOK_FSTRING_MODE;
|
||||||
|
|
Loading…
Reference in New Issue