From 591d2bd366676e935b2d8309f73a650df12d91b2 Mon Sep 17 00:00:00 2001 From: Lysandros Nikolaou Date: Thu, 6 Apr 2023 17:03:58 +0200 Subject: [PATCH] Preserve double open-braces in format specs --- Parser/tokenizer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index c294d837e88d85..060a9c73d2726f 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -2523,9 +2523,10 @@ tok_get_fstring_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct end_quote_size = 0; } + int in_format_spec = current_tok->last_expr_end != -1 && current_tok->bracket_mark_index >= 0; if (c == '{') { char peek = tok_nextc(tok); - if (peek != '{') { + if (peek != '{' || in_format_spec) { tok_backup(tok, peek); tok_backup(tok, c); current_tok->bracket_mark[++current_tok->bracket_mark_index] = current_tok->bracket_stack; @@ -2549,7 +2550,6 @@ tok_get_fstring_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct // scanning (indicated by the end of the expression being set) and we are not at the top level // of the bracket stack (-1 is the top level). Since format specifiers can't legally use double // brackets, we can bypass it here. - int in_format_spec = current_tok->last_expr_end != -1 && current_tok->bracket_mark_index >= 0; if (peek == '}' && !in_format_spec) { p_start = tok->start; p_end = tok->cur - 1;