There are some related issues:
But the problem is still the same. When a generator is passed to asyncio.gather, the expected return type should be Future[list[_T]]. However, it currently returns Future[tuple[_T1]], leading to type hinting warnings. This is a common pattern in asyncio code, and every time it cause unnecessary warnings in IDEs
Example code snippet:
async def fetch(url: str) -> str:
pass # fetch logic
def analyze(responses: list[str]) -> int:
pass # analyze logic that need all responses, maybe external library
async def create_report(urls: list[str]):
responses = await asyncio.gather(*(
fetch(url)
for url in urls
))
some_value = analyze(responses)
# create report

I read tasks.pyi file, but a significant number of developers use asyncio.gather(*[...]). So this behavior should be reviewed
Although practicality beats purity
(c) The Zen of Python
There are some related issues:
But the problem is still the same. When a generator is passed to
asyncio.gather, the expected return type should beFuture[list[_T]]. However, it currently returnsFuture[tuple[_T1]], leading to type hinting warnings. This is a common pattern in asyncio code, and every time it cause unnecessary warnings in IDEsExample code snippet:
I read tasks.pyi file, but a significant number of developers use
asyncio.gather(*[...]). So this behavior should be reviewed