Skip to content

Conversation

@sobolevn
Copy link
Member

@sobolevn sobolevn commented Jan 5, 2022

@hauntsaninja
Copy link
Collaborator

Thanks, you're right that this one doesn't need to be done in the sync PR since it'll pass on master

@sobolevn sobolevn mentioned this pull request Jan 5, 2022
@sobolevn
Copy link
Member Author

sobolevn commented Jan 5, 2022

@hauntsaninja is there anything else I should do? 🙂

@hauntsaninja
Copy link
Collaborator

Nope, this one was straightforward and I had covered. If you want, you could look into what's going on with type inference in testAsyncioGatherPreciseType in the "Sync typeshed" PR, but feel free not to!

@hauntsaninja hauntsaninja merged commit edbc248 into python:master Jan 5, 2022
@sobolevn
Copy link
Member Author

sobolevn commented Jan 6, 2022

@hauntsaninja it looks like this happens because gather uses tuple and list as return types. Overload logic does not like this, here:

inferred_result = self.infer_overload_return_type(plausible_targets, args, arg_types,

So, the common return type is infered there as Future[Any].

import asyncio

reveal_type(asyncio.gather)
reveal_type(asyncio.gather(*[asyncio.sleep(1), asyncio.sleep(1)]))

Stub for gather (simplified):

@overload
def gather(*coros_or_futures: _FutureT[Any], return_exceptions: bool = ...) -> Future[list[Any]]: ...
@overload
def gather(__coro_or_future1: _FutureT[_T1], *, return_exceptions: Literal[False] = ...) -> Future[tuple[T1]]: ...
[def (*coros_or_futures: Union[asyncio.futures.Future[Any], typing.Generator[Any, None, Any], typing.Awaitable[Any]], *, return_exceptions: builtins.bool =) -> asyncio.futures.Future[builtins.list[Any]], def [_T1] (Union[asyncio.futures.Future[_T1`-1], typing.Generator[Any, None, _T1`-1], typing.Awaitable[_T1`-1]], *, return_exceptions: Literal[False] =) -> asyncio.futures.Future[builtins.int]]
(asyncio.futures.Future[Any], def (*Any, **Any) -> Any)

out/ex.py:3: note: Revealed type is "Overload(def (*coros_or_futures: Union[asyncio.futures.Future[Any], typing.Generator[Any, None, Any], typing.Awaitable[Any]], *, return_exceptions: builtins.bool =) -> asyncio.futures.Future[builtins.list[Any]], def [_T1] (Union[asyncio.futures.Future[_T1`-1], typing.Generator[Any, None, _T1`-1], typing.Awaitable[_T1`-1]], *, return_exceptions: Literal[False] =) -> asyncio.futures.Future[builtins.int])"

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Jan 6, 2022

@sobolevn but the type of asyncio.gather has not changed in #11905 , only the type of asyncio.sleep has

https://github.com/python/mypy/pull/11905/files#diff-04a6e8e72f5ccf748662e8786571059eccb8154c46a42135c26127862e756870

tushar-deepsource pushed a commit to DeepSourceCorp/mypy that referenced this pull request Jan 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants