Skip to content

"Incompatible types" for asyncio.wait() + run_in_executor() #1940

@neilconway

Description

@neilconway

Sample program:

import asyncio
from typing import Any, Dict


async def message_reader(socket: Any) -> Any:
    return await socket.recv()


def do_work() -> Dict[str, Any]:
    return {}

async def foo(socket: Any) -> None:
    loop = asyncio.get_event_loop()
    work_task = loop.run_in_executor(None, do_work)
    recv_task = asyncio.ensure_future(message_reader(socket))
    pending = {work_task, recv_task}

    done, pending = await asyncio.wait(pending)

Error:

$ mypy --strict wait_mypy.py
wait_mypy.py:19: error: Incompatible types in assignment (expression has type "Set[Future[Any]]", variable has type "Set[Iterable[Any]]")
wait_mypy.py:19: error: Argument 1 to "wait" has incompatible type "Set[Iterable[Any]]"; expected "Iterable[Union[Generator[Any, None, <nothing>], Awaitable[<nothing>]]]"
wait_mypy.py:19: error: Argument 1 to "wait" has incompatible type "Set[Iterable[Any]]"; expected "Iterable[Union[Generator[Any, None, Any], Awaitable[Any]]]"
$ mypy --version
mypy 0.570

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions