← index #17075Issue #15216
Duplicate · high · value 2.457
QUERY · ISSUE

Syntax Error when using multiline f-strings on RP2040 with MicroPython v1.23.0

openby kpg141260opened 2025-04-04updated 2025-10-03
bugproposed-close

Port, board and/or hardware

RP2040 Raspberry Pi Pico

MicroPython version

MicroPython Version: v1.23.0 (2024-06-02)
RP2040 Platform: Raspberry Pi Pico
Python Version: MicroPython (RP2040)
Firmware: v1.23.0
Hardware: Raspberry Pi Pico (RP2040)

Reproduction

msg = (
    f'One ' 
    f'Two ' 
    f'Three'
)

print(msg)

Expected behaviour

The above code should print the concatenated string One Two Three without any syntax errors, similar to how it works in standard Python environments.

Observed behaviour

SyntaxError: invalid syntax

Additional Information

This issue persists even when re-typing the code, leading me to suspect it might be an issue with the way multiline f-strings are handled on this particular platform.

The issue can be resolved by concatenating the f-strings manually using +:

msg = (
    f'One ' +
    f'Two ' +
    f'Three'
)

print(msg)

Workaround:

Using string concatenation (as shown above) works, but this is not as elegant and adds unnecessary complexity compared to expected behaviour.

What else I have tried:

Testing with other Python environments (such as standard Python 3.x) shows that the multiline f-string works as expected.

This issue does not occur with simpler, single-line f-strings.
Ensuring no invisible characters or incorrect syntax in the code.

Code of Conduct

Yes, I agree

CANDIDATE · ISSUE

py: Error freezing a python source file with concatenated f-strings

closedby kdschlosseropened 2024-06-05updated 2024-06-06
bug

Port, board and/or hardware

any

MicroPython version

1.23.0

Reproduction

This error happens if you freeze a python source file with code like what is seen below.


TEST1 = 'Test1'
TEST2 = 'Test2'
TEST3 = 'Test3'

print(
    f'{TEST1}, '
    f'{TEST2}, '
    f'{TEST3}'
)

The error is "invalid syntax"

If I change the code to the following no errors occur.

TEST1 = 'Test1'
TEST2 = 'Test2'
TEST3 = 'Test3'

print(f'{TEST1}, {TEST2}, {TEST3}')

the error occurs because of the formatted text being on multiple lines. This is correct python syntax and I am not sure why it fails. If I do this there is no error.

print(
    'Test1, '
    'Test2, '
    'Test3'
)

the problem only occurs when using the format specifier.

Expected behaviour

For the code to properly run.

Observed behaviour

Syntax Error occurs

Additional Information

I am not sure if there is an error if I am not freezing the file. For some reason I believe that it does still occur if I run the source file instead of freezing it.

Code of Conduct

Yes, I agree

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