Closed krzotr closed 1 month ago
Thanks for the report.
This limitation is actually documented as a difference to CPython: https://docs.micropython.org/en/latest/genrst/core_language.html#f-strings-don-t-support-concatenation-with-adjacent-literals-if-the-adjacent-literals-contain-braces
Oh, I am sorry, I haven't read the whole documentation yet.
Port, board and/or hardware
windows port, linux port, esp32
MicroPython version
MicroPython 91f4a6b on 2024-08-08; linux [GCC 14.0.1] version MicroPython 91f4a6b on 2024-08-08; win32 [GCC 14.1.1] version MicroPython 91f4a6b on 2024-08-08; LILYGO TTGO LoRa32 with ESP32
Reproduction
After run code
I got:
Expected behaviour
I should see the output:
Observed behaviour
Regarding documentation String concatenation
If you use
"string" + f"string"
behavior should be the same as"string" f"string"
(concat without+
sign)I split a very long message
string and f-string
(over 130 characters to max 80) and passed it directly as a parameter to the function. I did not add+
, because I thought there was no difference.As you see
string and f-string
(concat without+
) becomesf-string
. If you put{
,}
characters in the first part of the expression you seeKeyError: NORMAL_STRING
because the whole expression becomes f-string.As a workaround, I always need to put
+
when concat strings and f-string to avoid conversion to f-string and exceptionKeyError
This works as expected:
Additional Information
In CPython 3.12 concatenation works in the same way as
+
and without - noKeyError
exceptionRelated issue #15216 - I build micropython 91f4a6b on 2024-08-08, so patch from #15216 is included
Code of Conduct
Yes, I agree