-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Poor handling of multi-line string literals using slash continuation #1183
Comments
If #1132 would fix this too, great 👍 |
(Reviewing this with black v22.1.0 now that the functionality is in a stable release) Input (with a hidden wrong assumption about the four spaces for indentation): if True:
# Pointless if-statement just for indentation here:
print("\
\nMESSAGE - printing a multi-line message to the user here as a single\
\nlong string literal taking multiple lines of Python source code.") With black v22.1.0 (no change from when I opened this issue), if True:
# Pointless if-statement just for indentation here:
print(
"\
\nMESSAGE - printing a multi-line message to the user here as a single\
\nlong string literal taking multiple lines of Python source code."
) With black v22.1.0 and if True:
# Pointless if-statement just for indentation here:
print(
" \nMESSAGE - printing a multi-line message to the user here as a single "
" \nlong string literal taking multiple lines of Python source code."
) Note that the original really does mean the output lines have four trailing spaces! This is probably a common user error, a wrong assumption about how the line continuation That means black with if True:
# Pointless if-statement just for indentation here:
print(
"\nMESSAGE - printing a multi-line message to the user here as a single"
"\nlong string literal taking multiple lines of Python source code."
) |
Describe the bug A clear and concise description of what the bug is.
To Reproduce Steps to reproduce the behavior:
I find this apparently mixed indentation very ugly, but it works and may be the least bad solution without removing the slash line continuation.
Expected behavior A clear and concise description of what you expected to happen.
The ideal output would be something like this, but would require black to break up string literals (already covered on separate issues like #182):
A possible compromise would be remove the slash continuation giving a long string:
The output is not ideal, but would be easy to spot with linters, and the behaviour is simple to explain.
Environment (please complete the following information):
Same on master checked with https://black.now.sh/?version=master
Additional context
This example is based on some real code https://github.com/biopython/biopython/blob/biopython-175/Scripts/Restriction/ranacompiler.py#L279 originally written in 2004.
The text was updated successfully, but these errors were encountered: