Black shouldn't merge multi-line string when last character on the line is '\n'
Author: ConchylicultorCreated Jul 9, 2020Updated Sep 13, 2026
LabelsT: styleF: strings
Describe the style change
It may be related to https://github.com/psf/black/issues/1467, but it seems #1467 is fixed when trying on https://black.now.sh/ while this one still fail.
Currently, string split in multiple lines are merged together.
Input:
ValueError(
'Invalid input:\n'
f' * x={x}\n'
f' * y={y}\n'
f' * z={z}'
)When the last character of the line is a \n, the code formatting match how the string will be displayed:
Invalid input:
* x=12
* y=41
* z=0Examples in the current Black style
Black merge all lines together, while keeping segments separated, which hurts readability:
ValueError("Invalid input:\n" f" * x={x}\n" f" * y={y}\n" f" * z={z}")Desired style
Black shouldn't merge the lines together and keep the original formatting:
ValueError(
'Invalid input:\n'
f' * x={x}\n'
f' * y={y}\n'
f' * z={z}'
)Source: psf/black