python-trio / trio-typing

Type hints for Trio and related projects
Other
27 stars 14 forks source link

Wrongly shows error message #7

Closed math2001 closed 5 years ago

math2001 commented 5 years ago

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?

oremanj commented 5 years ago

This is a mypy bug: https://github.com/python/mypy/issues/6492

I should probably update the README to list something that actually works. :-) Sorry this one bit you!

oremanj commented 5 years ago

Filed #9 to track the doc fix, so closing this issue.