Skip to content

Wrongly shows error message #7

Description

@math2001

Here's an example from the documentation:

import trio
from typing import List
from trio.testing import open_stream_to_socket_listener


async def handler(stream: trio.abc.Stream) -> None:
    print(await stream.receive_some(1024))


async def main() -> None:
    async with trio.open_nursery() as nursery:
        # the problematic line
        listeners: List[trio.SocketListener] = await nursery.start(
            trio.serve_tcp, handler, 0
        )
        client_stream = await open_stream_to_socket_listener(listeners[0])

        # Then send and receive data on 'client_stream', for example:
        await client_stream.send_all(b"GET / HTTP/1.0\r\n\r\n")


trio.run(main)

mypy complains with this error message:

test1.py:
 12:54  error  mypy  Argument 1 to "start" of "Nursery" has incompatible type "Callable[[Callable[[SocketStream], Awaitable[None]], int, DefaultNamedArg(Optional[AnyStr], 'host'),
                     DefaultNamedArg(Optional[int], 'backlog'), DefaultNamedArg(Optional[Nursery], 'handler_nursery'), NamedArg(TaskStatus[Sequence[SocketListener]], 'task_status')], Coroutine[Any, Any,
                     NoReturn]]"; expected <union: 5 items>

but the code runs fine... Am I missing something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions