-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Bug hazard - multiple strings given same indentation #4249
Comments
What you describe isn't actually Black's current style. It will put all the strings on line because they're short enough:
If you use the magic trailing comma to force each argument on its own line, the two implicitly concatenated strings are kept together, making it fairly clear that they belong together:
Your example reproduces only when the strings are too long for the line length:
Now, we previously implemented the behavior you request, but reverted it in #3640 for stability reasons. Might be worth revisiting though. |
Yeah, I guess I deal with long lines a lot. The most recent use case where this came up was a bulleted list of sentences, so its much harder to notice when a bullet combines with a previous one. Would happy if its just a config option. The fact its a bug hazard is why I am suggesting it just be the default behavior. |
Describe the style change
Strings that are concatenated together are always enclosed in parenthesis.
Examples in the current Black style
Desired style
Additional context
This isn't just a bug hazard where you accidentally join strings in an
*args
function. I frequently split strings that are too long by simply adding a""
at the split point and let black fix it. However, this doesn't format the way I want, so I have to spend time manually adding parenthesis around it.Also, both styles are currently accepted by black. I'm suggesting the first one should be rejected. I would be happy if there was an option to do this, and would be even happier if its already an option and I'm just not aware of it :)
In typical usage, the bug is harder to spot because the strings are often longer and the comma is all the way on the right-side of the editor. When you have mixed styles where some of the joins are intentional, its even harder to spot the bug.
The text was updated successfully, but these errors were encountered: