pylint icon indicating copy to clipboard operation
pylint copied to clipboard

consider-using-generator / R1728 false positive for "AsyncGenerator" valid code

Open simon-liebehenschel opened this issue 3 years ago • 0 comments

Bug description

Some simple valid Python code for demonstration purposes:

import asyncio

async def main():
    async def my_gen():
        for _ in range(10):
            yield _

    result = tuple([_ async for _ in my_gen()])
    print(result)

asyncio.run(main())

Pylint asks me to write

    result = tuple(_ async for _ in my_gen())

which is wrong because you will get an error TypeError: 'async_generator' object is not iterable

Configuration

No response

Command used

pre-commit run --all-files

Pylint output

R1728: Consider using a generator instead 'tuple(artist async for artist in artists)' (consider-using-generator)

Expected behavior

Pylint must understand that AsyncGenerator is used here and pylint must show no warnings.

Pylint version

pylint 2.14.5
astroid 2.11.7
Python 3.10.4 (main, Jun 29 2022, 12:14:53) [GCC 11.2.0]

OS / Environment

No response

Additional dependencies

No response

simon-liebehenschel avatar Aug 06 '22 18:08 simon-liebehenschel