Cannot parse multiline f-string starting with backslash `\`
Closed this issue · 2 comments
Describe the bug
Black fails to parse a file containing a multiline f-string that starts with a backslash \
To Reproduce
For example, take this code:
print """\
This is a multiline string\
"""
And paste into https://black.vercel.app/?version=main
The resulting error is:
Cannot parse: 1:6: print """\
Example:
Expected behavior
Successfully parse.
Environment
- Black's version: 24.4.2
- OS and Python version: psf/black@stable
Locally, I am using Python 2.7.18 but the issue occurs in the GitHub Action.
Additional context
Reused material from #4337.
Locally, I am using Python 2.7.18
We no longer support formatting Python 2 (https://black.readthedocs.io/en/stable/faq.html#which-python-versions-does-black-support). If you use Python 3 syntax, Black will format this fine.
Ah, sorry. Thank-you.
Edit: I got it to pass by using parentheses with the print()
call:
import sys
if len(sys.argv) < 2:
print(
"""\
Something something\
"""
)