-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect return type for asyncio.gather? #2652
Comments
Looking at the implementation of All fixes I can see have other downsides. |
Can't think of any better solution right now. I feel like it is better to lose type information than have it wrong. Were there any similar issues in the past? |
I've just ran into this one, and I agree that |
Is the base issue here that the return type of |
Nevermind, I poked around about in tasks.pyi and I see that the problem I'm getting locally has to do with my interpreter version running LSP not being the version I expect, I see the issue. |
Would |
No, because TypeVarTuple can't be used to type a heterogeneous list. |
Edit: I misunderstood this issue for something else. The tuple to list issue by OP is still present. And the problem is fundamental enough that I don't see a viable fix that avoids the downsides already mentioned. However, #9678 still improved things significantly where there's more possible workarounds that don't require casting or ignoring, but have a runtime cost: # Hide the tuples behind an iterable
async def runner() -> list[int]:
fives = await asyncio.gather(*[five(), five(), five()]) # not efficient, more of a demonstration for `Iterable[int]`
return fives
# Explicitly convert to list now that type is inferred
async def runner() -> list[int]:
fives = list(await asyncio.gather(five(), five(), five()))
return fives |
To summarize, we have to make a tradeoff here:
We've chosen the second option, and I think that's still the right tradeoff, since in my experience it's common to immediately unpack the return value of |
asyncio.gather
return type fromtasks.pyi
seem to be different from the actual runtime type.example.py
By looking at
tasks.pyi
I see no overload or any case wheregather
does not return aTuple
.The text was updated successfully, but these errors were encountered: