python-trio / trio-typing

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

trio.open_memory_channel requires explicit type declaration #6

Closed math2001 closed 5 years ago

math2001 commented 5 years ago
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 commented 5 years ago

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 commented 5 years ago

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.