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: With Item parentheses #7243

Closed
MichaReiser opened this issue Sep 8, 2023 · 4 comments
Closed

Formatter: With Item parentheses #7243

MichaReiser opened this issue Sep 8, 2023 · 4 comments
Assignees
Labels
accepted Ready for implementation bug Something isn't working formatter Related to the formatter

Comments

@MichaReiser
Copy link
Member

Input

if True:
    with (
        anyio.CancelScope(shield=True)
        if get_running_loop()
        else contextlib.nullcontext()
    ):
        pass

if True:
    with (
        anyio.CancelScope(shield=True)
        and B and [aaaaaaaa, bbbbbbbbbbbbb, cccccccccc, dddddddddddd, eeeeeeeeeeeee]
    ):
        pass

Black

if True:
    with (
        anyio.CancelScope(shield=True)
        if get_running_loop()
        else contextlib.nullcontext()
    ):
        pass

if True:
    with (
        anyio.CancelScope(shield=True)
        and B
        and [aaaaaaaa, bbbbbbbbbbbbb, cccccccccc, dddddddddddd, eeeeeeeeeeeee]
    ):
        pass

Ruff

if True:
    with anyio.CancelScope(
        shield=True
    ) if get_running_loop() else contextlib.nullcontext():
        pass

if True:
    with anyio.CancelScope(shield=True) and B and [
        aaaaaaaa,
        bbbbbbbbbbbbb,
        cccccccccc,
        dddddddddddd,
        eeeeeeeeeeeee,
    ]:
        pass

Expected

Ruff uses the maybe_parenthesize (can omit optional parentheses) layout where black seems not to.

I'm not sure if I agree with this choice because Black/Ruff use the maybe_parenthesize layout consistently in all other clause header positions.

@MichaReiser MichaReiser added formatter Related to the formatter needs-decision Awaiting a decision from a maintainer labels Sep 8, 2023
@MichaReiser MichaReiser added this to the Formatter: Beta milestone Sep 8, 2023
@charliermarsh
Copy link
Member

This is a bug -- we should be preserving the parentheses. We do the right thing with if statements:

if True:
    with (
        anyio.CancelScope(shield=True)
        if get_running_loop()
        else contextlib.nullcontext()
    ):
        pass

if True:
    if (
        anyio.CancelScope(shield=True)
        if get_running_loop()
        else contextlib.nullcontext()
    ):
        pass

@charliermarsh charliermarsh added bug Something isn't working and removed needs-decision Awaiting a decision from a maintainer labels Sep 27, 2023
@charliermarsh
Copy link
Member

Not a blocker for the Beta, but we may fix it anyway this month.

@charliermarsh charliermarsh added the accepted Ready for implementation label Sep 27, 2023
@charliermarsh
Copy link
Member

Not totally trivial in part due to the as.

@MichaReiser MichaReiser self-assigned this Sep 28, 2023
@charliermarsh
Copy link
Member

I believe this was closed by #7694.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Ready for implementation bug Something isn't working formatter Related to the formatter
Projects
None yet
Development

No branches or pull requests

2 participants