interpy icon indicating copy to clipboard operation
interpy copied to clipboard

Parsing fails when using implicit string concatenation

Open tedmiston opened this issue 9 years ago • 2 comments

This concatenation style is valid and commonly use for multiline strings.

x = (
    "foo"
    "bar"
)
print x

output:

foobar

However it breaks when a variable interpolation is added:

# coding: interpy

a = 5
x = (
    "foo #{a}"
    "bar"
)
print x

output:

  File "test.py", line 6
    "bar"
        ^
SyntaxError: invalid syntax

I expected the output:

foo5bar

tedmiston avatar Nov 17 '15 04:11 tedmiston

Since the bytecode generation converts the interpolation to addition, this would certainly seem to fail.

The code above is converted to:

x = (
    "foo " + str(a)
    "bar"
)

This sounds like a very common pitfall.

prashnts avatar Feb 23 '16 19:02 prashnts

@PrashntS I would agree. I stopped using the library for that reason.

tedmiston avatar Feb 23 '16 20:02 tedmiston