py/lexer: Fix parsing of f'{{'.

Prior to this fix, f'{{' would raise a SyntaxError.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2026-03-04 22:43:23 +11:00
parent b343a3697c
commit 58436b2882
2 changed files with 6 additions and 0 deletions

View File

@@ -408,6 +408,7 @@ static void parse_string_literal(mp_lexer_t *lex, bool is_raw, bool is_fstring)
vstr_add_byte(&lex->fstring_args, ',');
}
vstr_add_byte(&lex->vstr, '{');
goto continue_outer;
}
#endif
@@ -518,6 +519,9 @@ static void parse_string_literal(mp_lexer_t *lex, bool is_raw, bool is_fstring)
}
continue_parsing_string_literal:
next_char(lex);
#if MICROPY_PY_FSTRINGS
continue_outer:;
#endif
}
// check we got the required end quotes

View File

@@ -31,6 +31,8 @@ print(f"a{ {0,1,2}}")
# PEP-0498 specifies that handling of double braces '{{' or '}}' should
# behave like str.format.
print(f'{{')
print(f'}}')
print(f'{{}}')
print(f'{{{4*10}}}', '{40}')