#4249·black

Bug hazard - multiple strings given same indentation

Author: JamesHutchisonCreated Feb 23, 2024Updated Sep 13, 2026
LabelsT: styleF: parenthesesF: strings

Describe the style change

Strings that are concatenated together are always enclosed in parenthesis.

Examples in the current Black style

python
some_func(
    "can you"
    "spot the bug",
    "in this list of strings",
    "where a comma is missing?"
)

Desired style

python
some_func(
    (
        "can you"
        "spot the bug"
    ),
    "in this list of strings",
    "where a comma is missing?"
)

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.