python-trio / trio-typing

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

Nursery.start_soon() doesn't accept a function returning a bool #16

Closed gsalgado closed 4 years ago

gsalgado commented 4 years ago
async def func() -> bool:
    return False

async def foo() -> None:
    async with trio.open_nursery() as n:
        n.start_soon(func)

Running mypy on the code above gives me this error:

error: Argument 1 to "start_soon" of "Nursery" has incompatible type "Callable[[], Coroutine[Any, Any, bool]]"; expected "Union[Callable[[], Awaitable[None]], Callable[[Any], Awaitable[None]], Callable[[Any, Any], Awaitable[None]], Callable[[Any, Any, Any], Awaitable[None]], Callable[[Any, Any, Any, Any], Awaitable[None]], Callable[[VarArg(Any)], Awaitable[None]]]"

If I change func()'s signature to return None/Any, it doesn't complain, but I don't see why start_soon() should require that?

I understand the return value of the func is discarded by start_soon(), but in my real code I sometimes run that same func with trio.gather(), in which case I want the return value