Skip to content

Bug: C419 incorrectly tries to remove list comprehension in async for #12891

@MarkusSintonen

Description

@MarkusSintonen

Following code gives an incorrect linting error:

from collections.abc import AsyncGenerator


async def test() -> None:
    async def async_gen() -> AsyncGenerator[bool, None]:
        yield True

    assert all([v async for v in async_gen()])  # C419 Unnecessary list comprehension

Removing the list comprehension here is incorrect as all can not take an async generator.
Changing it into all(v async for v in async_gen()) gives: TypeError: 'async_generator' object is not iterable

Using Ruff version 0.5.7.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedContributions especially welcome

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions