Return coroutine from AsyncGenerator.__anext__ (#12685)

The `__anext__` method of an asynchronous generator defined using the
`async def`/`yield` syntax returns an actual coroutine not just any
awaitable. Let the definition of the `AsyncGenerator` protocol reflect
this circumstance.

See https://discuss.python.org/t/types-for-asynchronous-generators-too-general/64515
for the motivation behind this change.
This commit is contained in:
Martin Huschenbett
2024-09-23 11:34:56 +02:00
committed by GitHub
parent bde71c575f
commit 46512118ea

View File

@@ -540,7 +540,7 @@ class AsyncIterator(AsyncIterable[_T_co], Protocol[_T_co]):
def __aiter__(self) -> AsyncIterator[_T_co]: ...
class AsyncGenerator(AsyncIterator[_YieldT_co], Generic[_YieldT_co, _SendT_contra]):
def __anext__(self) -> Awaitable[_YieldT_co]: ...
def __anext__(self) -> Coroutine[Any, Any, _YieldT_co]: ...
@abstractmethod
def asend(self, value: _SendT_contra, /) -> Coroutine[Any, Any, _YieldT_co]: ...
@overload