-
Notifications
You must be signed in to change notification settings - Fork 16
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
Error triggering on this function but why? #48
Comments
To simplify this somewhat. |
I think the issue is that py-backwards converts f"Hello {key: >10} {x: >5} world" into ''.join(['Hello ', '{: >10}'.format(key), ' ', '{: >5}'.format(x), ' world']) So, basically treating each A possible solution would be to convert instead to: "Hello {key: >10} {x: >5} world".format(**{**locals(), **globals()}) which simply requires finding all f-strings, removing the f, and appending an expression that is always the same. I think that's likely to always work, but maybe there's a performance hit (though I suspect the actual string formatting is slower than merging two dictionaries). I tested the specific case above, and the following two expressions both work and give equivalent results: f"{key: >{width}} string" # Python 3.6
"{key: >{width}} string".format(**{**locals(), **globals()}) # Converted to Python 3.5 |
Oh, I realize you need to put the actual expressions in the arguments (since f-strings allow expressions inside the curly braces). So it would have to be something like: f"{key: >{width + 2}} string" # Python 3.6
"{a: >{b}} string".format(a=key, b=width + 2) # Converted to Python 3.5 which means you'll need to parse the nested curly braces anyway. |
The following code can't be converted from 3.6 to python 3.5 and the error seems to stem from something in py-backwards, I just can't figure out what.
I tried it in the online demo and it blew up.
If I remove the following code it works,
bit this peace breaks something. Without triggering a syntax error.
The code comes from this project and file: https://github.com/linnarsson-lab/loompy/blob/master/loompy/loom_validator.py
What is going on here?
The text was updated successfully, but these errors were encountered: