str.center() bug with unicode characters
Port, board and/or hardware
Raspberry Pico; Linux PC
MicroPython version
MicroPython v1.25.0 on 2025-04-15; Raspberry Pi Pico W with RP2040
MicroPython v1.22.1+ds-1build2 on 2024-04-01; linux [GCC 13.2.0]
Reproduction
Run this code in REPL or separately:
print(len('°'.center(4)))
Expected behaviour
Expected to output 4
Observed behaviour
Outputs 3
Additional Information
No, I've provided everything above.
Code of Conduct
Yes, I agree
Syntax Error when using multiline f-strings on RP2040 with MicroPython v1.23.0
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