Skip to content

Formatter: parenthesize_conditional_expressions preview style #8438

@zanieb

Description

@zanieb

Implement Black's parenthesize_conditional_expressions style as a preview style in Ruff.

Note: This new style might not be accepted as part of Black's 2024 style guide.

Unformatted:

[
    "____________________________",
    "foo",
    "bar",
    "baz" if some_really_looooooooong_variable else "some other looooooooooooooong value"
]

Formatted (Black stable, Ruff):

[
    "____________________________",
    "foo",
    "bar",
    "baz"
    if some_really_looooooooong_variable
    else "some other looooooooooooooong value",
]

Formatted (Black preview):

[
    "____________________________",
    "foo",
    "bar",
    (
        "baz"
        if some_really_looooooooong_variable
        else "some other looooooooooooooong value"
    ),
]

When it fits again...

Formatter (Ruff, Black stable, Black preview):

[
    "____________________________",
    "foo",
    "bar",
    ("baz" if some_really_looooooooong_variable else "some other loooooooooong value"),
]

Arguably, these should be removed to ensure the formatting is reversible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    formatterRelated to the formatterpreviewRelated to preview mode featuresstyleHow should formatted code look

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions