← index #8606Issue #8450
Off-topic · high · value 0.279
QUERY · ISSUE

Spaces in f-strings can cause incorrect SyntaxErrors

openby mattytrentiniopened 2022-05-02updated 2026-03-22
py-core

Here are two examples of valid f-strings that currently raise SyntaxErrors:

>>> x = 10
>>> f"{x = }"
SyntaxError: invalid syntax
>>> f"{x = :.3f}"
SyntaxError: invalid syntax

Removing the spaces between the curlies is the recommended workaround.

(The examples were found when browsing Python f-strings Are More Powerful Than You Might Think)

These issues should either be documented (in cpydiff) or resolved.

To resolve, see the comment in https://github.com/micropython/micropython/commit/692d36d779192f32371f7f9daa845b566f26968d for background. A solution may be possible by modifying the lexer to strip spaces from the f-string before translating it to str.format.

CANDIDATE · ISSUE

f-string feature missing on esp8266 with 1MiB flash port, throws SyntaxError: invalid syntax

closedby Kyuchumimoopened 2022-03-25updated 2022-03-25
port-esp8266

Code example:

string = "F-STRING"

print(f"{string} OK")

see: https://github.com/micropython/micropython/releases/tag/v1.18
...

esp8266 port:

  • boards/GENERIC: enable f-strings
    ...

...

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied