mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
[3.12] gh-122026: Fix identification of mismatched parentheses inside f-strings (GH-122028) (#122062)
(cherry picked from commit 2009e25e26
)
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
This commit is contained in:
parent
0298da432d
commit
966eff9ce4
3 changed files with 6 additions and 0 deletions
|
@ -921,6 +921,7 @@ x = (
|
|||
"f'{:2}'",
|
||||
"f'''{\t\f\r\n:a}'''",
|
||||
"f'{:'",
|
||||
"F'{[F'{:'}[F'{:'}]]]",
|
||||
],
|
||||
)
|
||||
|
||||
|
|
|
@ -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
|
|
@ -2607,6 +2607,9 @@ letter_quote:
|
|||
|
||||
if (INSIDE_FSTRING(tok)) {
|
||||
current_tok->curly_bracket_depth--;
|
||||
if (current_tok->curly_bracket_depth < 0) {
|
||||
return MAKE_TOKEN(syntaxerror(tok, "f-string: unmatched '%c'", c));
|
||||
}
|
||||
if (c == '}' && current_tok->curly_bracket_depth ==
|
||||
current_tok->curly_bracket_expr_start_depth) {
|
||||
current_tok->curly_bracket_expr_start_depth--;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue