Skip to content

assertion with multi-line string needlessly spans multiple lines #4247

@Aran-Fey

Description

@Aran-Fey

Describe the bug

When an assert statement has a multi-line string, the condition is split across 3 lines for no reason.

To Reproduce

For example, take this code:

assert some_var == expected_result, f"""
expected: {expected_result}
actual: {some_var}"""

And run it with these arguments:

$ black file.py

The resulting output is:

assert (
    some_var == expected_result
), f"""
expected: {expected_result}
actual: {some_var}"""

Expected behavior

The condition should remain as a single line.

Environment

Metadata

Metadata

Assignees

No one assigned

    Labels

    T: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions