Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Wrongly shows error message #7

Closed
math2001 opened this issue Apr 27, 2019 · 2 comments
Closed

Wrongly shows error message #7

math2001 opened this issue Apr 27, 2019 · 2 comments

Comments

@math2001
Copy link
Member

math2001 commented Apr 27, 2019

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
Copy link
Member

oremanj commented Apr 29, 2019

This is a mypy bug: python/mypy#6492

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

@oremanj
Copy link
Member

oremanj commented Apr 29, 2019

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

@oremanj oremanj closed this as completed Apr 29, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants