Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

trio.open_memory_channel requires explicit type declaration #6

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

trio.open_memory_channel requires explicit type declaration #6

math2001 opened this issue Apr 20, 2019 · 2 comments

Comments

@math2001
Copy link
Member

sendch, getch = trio.open_memory_channel(0)

mypy wants

sendch, getch = trio.open_memory_channel(0) # type: trio.abc.SendChannel, trio.abc.ReceiveChannel

Shouldn't mypy be able to infer the types by itself?

@math2001
Copy link
Member Author

I just looked at the source code, and saw this line. So, I had to do this:

sendch, getch = trio.open_memory_channel[sometype](0)

Was this documented somewhere I missed? Maybe it should be added to the README.

@oremanj
Copy link
Member

oremanj commented Apr 29, 2019

The error message that mypy produces is Need type annotation for '<name of variable>', which is the same error you get if you write some_list = [] in a context where mypy can't infer the type. The solution in both cases is to add the type parameter.

I agree that this error is confusing; filed #9 to track the documentation improvement that's needed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants