Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatter: parenthesize_conditional_expressions preview style #8438

Closed
Tracked by #6935 ...
zanieb opened this issue Nov 2, 2023 · 1 comment
Closed
Tracked by #6935 ...

Formatter: parenthesize_conditional_expressions preview style #8438

zanieb opened this issue Nov 2, 2023 · 1 comment
Labels
formatter Related to the formatter preview Related to preview mode features style How should formatted code look

Comments

@zanieb
Copy link
Member

zanieb commented Nov 2, 2023

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.

@zanieb zanieb added formatter Related to the formatter preview Related to preview mode features style How should formatted code look labels Nov 2, 2023
@zanieb zanieb added this to the Formatter: Stable milestone Nov 2, 2023
@MichaReiser MichaReiser changed the title Formatter: Parenthesize long expressions in lists Formatter: parenthesize_conditional_expressions preview style Nov 29, 2023
@MichaReiser
Copy link
Member

We don't plan to implement this preview style as part of Ruff's 2024 style guide because we believe that improving the binary expression formatting solves the problem more holistically. See psf/black#4123 for the details

@MichaReiser MichaReiser removed this from the Formatter: Stable milestone Dec 22, 2023
@MichaReiser MichaReiser closed this as not planned Won't fix, can't repro, duplicate, stale Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the formatter preview Related to preview mode features style How should formatted code look
Projects
None yet
Development

No branches or pull requests

2 participants