Skip to content

Formatter: improved_async_statements_handling preview style #8890

@MichaReiser

Description

@MichaReiser

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    formatterRelated to the formatterpreviewRelated to preview mode features

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions