-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Multiline string formatting. It this intended behavior? #397
Comments
I'm not the maintainer and not confident but it seems to be intended.
PEP 8 says:
https://www.python.org/dev/peps/pep-0008/#maximum-line-length So either of the following patterns are recommended for your case, I believe: a = (
"&SortByValue=priority&SortByOrder=asc"
+ "&IndexToStartPaging={3}"
+ "&NumberOfElementsToShow={2}"
+ "&CacheDurationMinutes=0"
+ "&AllowAlternativeResults=false"
) a = (
"&SortByValue=priority&SortByOrder=asc"
"&IndexToStartPaging={3}"
"&NumberOfElementsToShow={2}"
"&CacheDurationMinutes=0"
"&AllowAlternativeResults=false"
) |
Thanks a lot for your response @gh640 . My surprise was not that Black corrects the use of backslashes. My surprise was with the output. Your two suggestions seem much better than what Black suggests. |
Thanks for reporting, this is already tracked under #330 |
I have a similar problem with formatting. IMHO black should at least support multi-lines strings where every line is a real line with a new line character. Example code and expected result after formatting:
Not intended and formatted code by black:
|
@ichard26 I found the following solution for my current case:
(note the |
It is a tuple, not a string. |
I was surprised to see Black change this:
to this:
a = "&SortByValue=priority&SortByOrder=asc" "&IndexToStartPaging={3}" "&NumberOfElementsToShow={2}" "&CacheDurationMinutes=0" "&AllowAlternativeResults=false"
I could understand joining it one string. Both are valid but second one looks weird to me. Is this intended? The output also breaks line length rule.
The text was updated successfully, but these errors were encountered: