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

Parsing fails when using implicit string concatenation #8

Open
tedmiston opened this issue Nov 17, 2015 · 2 comments
Open

Parsing fails when using implicit string concatenation #8

tedmiston opened this issue Nov 17, 2015 · 2 comments

Comments

@tedmiston
Copy link

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
@prashnts
Copy link

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.

@tedmiston
Copy link
Author

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

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