Skip to content

Black shouldn't merge multi-line string when last character on the line is '\n' #1540

@Conchylicultor

Description

@Conchylicultor

Describe the style change

It may be related to #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=0

Examples 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}'
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    F: stringsRelated to our handling of stringsT: styleWhat do we want Blackened code to look like?

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions