From fb8792c095802a9fcc8b38c1d8cbc3f641918433 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Wed, 19 Oct 2022 11:30:28 +1100 Subject: py/lexer: Wrap in parenthesis all f-string arguments passed to format. This is important for literal tuples, e.g. f"{a,b,}, {c}" --> "{}".format((a,b), (c),) which would otherwise result in either a syntax error or the wrong result. Fixes issue #9635. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- tests/basics/string_fstring.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests/basics/string_fstring.py') diff --git a/tests/basics/string_fstring.py b/tests/basics/string_fstring.py index 7e8a97fd3..8907a5c47 100644 --- a/tests/basics/string_fstring.py +++ b/tests/basics/string_fstring.py @@ -56,3 +56,8 @@ try: except (ValueError, SyntaxError): # MicroPython incorrectly raises ValueError here. print('SyntaxError') + +# Allow literal tuples +print(f"a {1,} b") +print(f"a {x,y,} b") +print(f"a {x,1} b") -- cgit v1.2.3