-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Describe the style change
I suggest to use explicit string concatenation, instead of implicit concatenation, for (currently experimental) string processing, with whitespace pushed to the end of each line.
Examples in the current Black style
(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor"
" incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis"
" nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
)
(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " # whitespace is split
" incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis"
" nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
)
(
"https://www.some-really-really-really-really-really-really-really-really-really-really-really-really-long-url.com"
)
Desired style
(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor "
+ "incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis "
+ "nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
)
(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " # whitespace is not split
+ "incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis"
+ "nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
)
(
"https://www.some-really-really-really-really-really-really-really-really-"
+ "really-really-really-really-long-url.com"
)
Additional context
Advantages of this method:
- Lines with multiple whitespace characters in a row line up nicely
- Lines with no whitespace can be split and still visually consistent (if desired)
- Plus sign indicates that this is a line continuation, not a list, without having to glance at previous line ending
- Avoid common coding errors by accidentally-left-out commas
- Compatible with linters [1 2 3] which forbid implicit concatenation to enforce consistency and/or to help avoid aforementioned coding errors
Worth noting that Guido & the Python community have considered removing implicit concatenation for these reasons, but ran into complications (here's an article about this). However, the reasons why they left it in the language (%
precedence, etc.) don't apply to whether Black uses the feature (for the %
precedence issue, it doesn't apply at least because the multiline strings are wrapped in parentheses), so I think that Black ought to use the explicit version.