-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Description
There are some related issues:
- More precisely typehint asyncio.gather up to 5 params #1550
- Clarification: return type for asyncio.gather()? #3243
- Incorrect return type for asyncio.gather? #2652
- And several questions on StackOverflow
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
Metadata
Metadata
Assignees
Labels
No labels