circuitpython/tests/basics/string_fstring_debug.py
Jim Mussared fb8792c095 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 <jim.mussared@gmail.com>
2023-01-20 17:54:32 +11:00

28 lines
355 B
Python

# test f-string debug feature {x=}
def f():
return 4
def g(_):
return 5
def h():
return 6
x, y = 1, 2
print(f"{x=}")
print(f"{x=:08x}")
print(f"a {x=} b {y} c")
print(f"a {x=:08x} b {y} c")
print(f'a {f() + g("foo") + h()=} b')
print(f'a {f() + g("foo") + h()=:08x} b')
print(f"a {1,=} b")
print(f"a {x,y,=} b")
print(f"a {x,1=} b")