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: wrap_multiple_context_managers_in_parens preview style #8889

Closed
Tracked by #8678
MichaReiser opened this issue Nov 29, 2023 · 2 comments · Fixed by #9222
Closed
Tracked by #8678

Formatter: wrap_multiple_context_managers_in_parens preview style #8889

MichaReiser opened this issue Nov 29, 2023 · 2 comments · Fixed by #9222
Assignees
Labels
formatter Related to the formatter preview Related to preview mode features

Comments

@MichaReiser
Copy link
Member

MichaReiser commented Nov 29, 2023

Implement Black's wrap_multiple_context_managers_in_parens as a preview style. The new style only applies to Py39+.

with \
     make_context_manager1() as cm1, \
     make_context_manager2() as cm2, \
     make_context_manager3() as cm3, \
     make_context_manager4() as cm4 \
:
    pass

Gets formatted as

with (
    make_context_manager1() as cm1,
    make_context_manager2() as cm2,
    make_context_manager3() as cm3,
    make_context_manager4() as cm4,
):
    pass

Black automatically detects the python version used in a file based on the syntax used. E.g. a file using match statements is Py310+. I'm unsure if we should autodetect the python version based on the syntax or rely on requires-python

@MichaReiser MichaReiser added formatter Related to the formatter preview Related to preview mode features labels Nov 29, 2023
@MichaReiser MichaReiser added this to the Formatter: Stable milestone Nov 29, 2023
@MichaReiser MichaReiser changed the title wrap_multiple_context_managers_in_parens: Requires Py39+ Formatter: wrap_multiple_context_managers_in_parens preview style Nov 29, 2023
@charliermarsh
Copy link
Member

I'm unsure if we should autodetect the python version based on the syntax or rely on requires-python.

I would prefer to stick to our existing configuration semantics, and not introduce any autodetection.

@charliermarsh
Copy link
Member

charliermarsh commented Dec 3, 2023

It looks like the original intent, per the docs, is to reformat as:

# Input
with make_context_manager1() as cm1, make_context_manager2() as cm2, make_context_manager3() as cm3, make_context_manager4() as cm4:
    pass

# < Python 3.9
with \
     make_context_manager1() as cm1, \
     make_context_manager2() as cm2, \
     make_context_manager3() as cm3, \
     make_context_manager4() as cm4 \
:
    pass

# >= Python 3.9
with (
    make_context_manager1() as cm1,
    make_context_manager2() as cm2,
    make_context_manager3() as cm3,
    make_context_manager4() as cm4,
):
    pass

But AFAICT Black only implemented the second piece, and not the continuation escapes.

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants