Implicit continuations with f-strings cause SyntaxErrors
tulir opened this issue · comments
Tulir Asokan commented
Line continuations that contain f-strings aren't properly transpiled.
Test script:
# -*- coding: future_fstrings -*-
a = 1
b = 2
# Escaped newline
c = f"a={a} " \
f"b={b}"
print(c)
# Implied line continuation inside parentheses
print(f"a={a} "
f"b={b}")
Output with Python 3.6:
a=1 b=2
a=1 b=2
Error with Python 3.5:
File "asd.py", line 6
"b={}".format((b))
^
SyntaxError: invalid syntax
Anthony Sottile commented
Ah indeed, some more clever for implicit continuation needs to be implemented.
Thanks for the report! :)
Anthony Sottile commented
If you want to hack on it, the problematic code is here:
This needs to continue to iterate forward until it finds a token that isn't either:
- name(f) followed by string
- a string
- an escaped newline
- whitespace
- newline
There's some interesting edge cases here that are more fiddly:
print('foo' f'bar {1}') # foobar 1
print(f'bar {1}' 'foo') # bar 1foo
print(f'foo {1}' 'bar {1}) # foo 1bar {1}
Anthony Sottile commented
@tulir please try out 0.4.2 which has a fix for this!
Tulir Asokan commented
Everything seems to work now, thanks!