Stub for redis.async.PubSub.listen():
|
async def listen(self) -> AsyncIterator[Any]: ... |
Actual Implementation:
async def listen(self) -> AsyncIterator:
"""Listen for messages on channels this client has been subscribed to"""
while self.subscribed:
response = await self.handle_message(await self.parse_response(block=True))
if response is not None:
yield response
Even though signatures are equivalent, mypy interprets the stub to be a coroutine that returns an AsyncIterator.
For example, this is runtime valid, but mypy finds an error:
async for message in pubsub.listen():
...
error: "Coroutine[Any, Any, AsyncIterator[Any]]" has no attribute "__aiter__" (not async iterable) [attr-defined]
This is invalid code, but passes mypy:
async for message in await pubsub.listen():
...
TypeError: object async_generator can't be used in 'await' expression
References:
Stub for
redis.async.PubSub.listen():typeshed/stubs/redis/redis/asyncio/client.pyi
Line 157 in 50da0aa
Actual Implementation:
Even though signatures are equivalent, mypy interprets the stub to be a coroutine that returns an
AsyncIterator.For example, this is runtime valid, but mypy finds an error:
This is invalid code, but passes mypy:
References: