Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concatenation of f-strings throws syntax error #7786

Closed
peterhinch opened this issue Sep 14, 2021 · 2 comments
Closed

Concatenation of f-strings throws syntax error #7786

peterhinch opened this issue Sep 14, 2021 · 2 comments

Comments

@peterhinch
Copy link
Contributor

From this forum thread - ignore incorrect title:

x = 1
y = 2
f"{x}" f"{y}"

On CPython this produces 12. On MicroPython Unix build:

MicroPython v1.17 on 2021-09-02; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> x = 1
>>> y = 2
>>> f"{x}" f"{y}"
Traceback (most recent call last):
  File "<stdin>", line 1
SyntaxError: invalid syntax
>>> 
@dpgeorge
Copy link
Member

This is a known limitation of f-strings in MicroPython. It's actually documented: http://docs.micropython.org/en/latest/genrst/core_language.html#f-strings-don-t-support-concatenation-with-adjacent-literals-if-the-adjacent-literals-contain-braces

@jimmo it seems there's a minor issue with that cpydiff, that "aa" f"abc" is not supported in CPy either.

@peterhinch
Copy link
Contributor Author

Apologies. I hadn't spotted that doc update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants