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

Improve formatting multiple context managers #8588

Closed
smurfix opened this issue Nov 9, 2023 · 2 comments
Closed

Improve formatting multiple context managers #8588

smurfix opened this issue Nov 9, 2023 · 2 comments
Labels
formatter Related to the formatter preview Related to preview mode features

Comments

@smurfix
Copy link

smurfix commented Nov 9, 2023

ruff --format currently reformats this code:

async with \
        Dispatch(obj.cfg, run=True, sig=True) as dsp, \
        dsp.cfg_at(*cfg["path"], *cfg_path) as cf, \
        dsp.sub_at(*cfg["path"], *fs_path) as fs:

as

async with Dispatch(obj.cfg, run=True, sig=True) as dsp, dsp.cfg_at(
        *cfg["path"],
        *cfg_path,
    ) as cf, dsp.sub_at(*cfg["path"], *fs_path) as fs:

This is … really unhelpful. It would be a lot nicer to add parentheses instead:

async with (
    Dispatch(obj.cfg, run=True, sig=True) as dsp,
    dsp.cfg_at(*cfg["path"], *cfg_path) as cf,
    dsp.sub_at(*cfg["path"], *fs_path) as fs,
):

which I currently need to do manually.

This syntax refinement was added in Py3.10.

@smurfix smurfix changed the title Prettify formatting multiple context managers Improve formatting multiple context managers Nov 9, 2023
@charliermarsh charliermarsh added formatter Related to the formatter preview Related to preview mode features labels Nov 9, 2023
@charliermarsh
Copy link
Member

Parenthesized context managers aren't supported on older versions of Python, but we will enforce this as part of implementing Black's preview style.

@MichaReiser
Copy link
Member

I'll close this because it is tracked in #8678 (see wrap_multiple_context_managers_in_parens)

@MichaReiser MichaReiser closed this as not planned Won't fix, can't repro, duplicate, stale Nov 27, 2023
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

No branches or pull requests

3 participants