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: improved_async_statements_handling preview style #8890

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

Formatter: improved_async_statements_handling preview style #8890

MichaReiser opened this issue Nov 29, 2023 · 0 comments · Fixed by #9222
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 same as improved_async_statements_handling as a preview style. This is the same as #8889 but for async context managers. Requires Py39+

async def func() -> (int):
    return 0


@decorated
async def func() -> (int):
    return 0


async for (item) in async_iter:
    pass

Formatted as (already implemented in ruff)

async def func() -> int:
    return 0


@decorated
async def func() -> int:
    return 0


async for item in async_iter:
    pass

and

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

    async with some_function(
        argument1, argument2, argument3="some_value"
    ) as some_cm, some_other_function(
        argument1, argument2, argument3="some_value"
    ):
        pass

gets formatted as

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

    async with (
        some_function(argument1, argument2, argument3="some_value") as some_cm,
        some_other_function(argument1, argument2, argument3="some_value"),
    ):
        pass
@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 improved_async_statements_handlingsame as wrap_multiple_context_managers_in_parens but for async with. Requires Py39+ Formatter: improved_async_statements_handlingpreview style Nov 29, 2023
@MichaReiser MichaReiser changed the title Formatter: improved_async_statements_handlingpreview style Formatter: improved_async_statements_handling preview style Nov 29, 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

Successfully merging a pull request may close this issue.

1 participant