diff --git a/pytype/stubs/builtins/builtins.pytd b/pytype/stubs/builtins/builtins.pytd index 0cccc43b0..b1e556cda 100644 --- a/pytype/stubs/builtins/builtins.pytd +++ b/pytype/stubs/builtins/builtins.pytd @@ -968,9 +968,9 @@ class coroutine(Coroutine[_T, _T2, _V]): class asyncgenerator(AsyncGenerator[_T, _T2]): __slots__ = [] def __aiter__(self) -> asyncgenerator[_T, _T2]: ... - def __anext__(self) -> Awaitable[_T]: ... - def asend(self, value: _T2) -> Awaitable[_T]: ... - def aclose(self) -> Awaitable[_T]: ... + def __anext__(self) -> coroutine[Any, Any, _T]: ... + def asend(self, value: _T2) -> coroutine[Any, Any, _T]: ... + def aclose(self) -> coroutine[Any, Any, None]: ... class instancemethod(object): __slots__ = [] diff --git a/pytype/stubs/builtins/typing.pytd b/pytype/stubs/builtins/typing.pytd index 76237b422..c4e821305 100644 --- a/pytype/stubs/builtins/typing.pytd +++ b/pytype/stubs/builtins/typing.pytd @@ -556,11 +556,13 @@ class AsyncContextManager(Generic[_T], Protocol): class AsyncGenerator(AsyncIterator[_T], Generic[_T, _T2]): __slots__ = [] @abstractmethod - def asend(self, value: _T2) -> Awaitable[_T]: ... + def __anext__(self) -> Coroutine[Any, Any, _T]: ... @abstractmethod - def athrow(self, typ: Type[BaseException], val = ..., tb = ...) -> Awaitable[_T]: ... + def asend(self, value: _T2) -> Coroutine[Any, Any, _T]: ... @abstractmethod - def aclose(self) -> Awaitable[_T]: ... + def athrow(self, typ: Type[BaseException], val = ..., tb = ...) -> Coroutine[Any, Any, _T]: ... + @abstractmethod + def aclose(self) -> Coroutine[Any, Any, None]: ... TYPE_CHECKING = ... # type: bool diff --git a/pytype/tests/test_async_generators.py b/pytype/tests/test_async_generators.py index 733dd225f..5a8b762b8 100644 --- a/pytype/tests/test_async_generators.py +++ b/pytype/tests/test_async_generators.py @@ -401,6 +401,20 @@ def g(i: Awaitable[str]): pass }, ) + @test_utils.skipBeforePy((3, 10), "New in 3.10") + def test_async_gen_coroutines(self): + self.Check(""" + from typing import Any, AsyncGenerator, Coroutine + async def gen(): + yield 42 + + x0: AsyncGenerator[int, None] = gen() + x1: Coroutine[Any, Any, int] = gen().__anext__() + x2: Coroutine[Any, Any, int] = gen().asend(None) + x3: Coroutine[Any, Any, int] = gen().athrow(BaseException) + x4: Coroutine[Any, Any, None] = gen().aclose() + """) + if __name__ == "__main__": test_base.main()