Hi! I was recently running some sample code in the async-tasks section of the docs. I noticed that the following example does not play nicely with VS Code / pyright. Given the current state of type hints in the project, I wasn’t sure if I should spam the repo with type related issues / PRs. Is this something I should report and/or submit a PR for?
import asyncio
from prefect import task, flow
@task
async def print_values(values):
for value in values:
await asyncio.sleep(1) # yield
print(value, end=" ")
@flow
async def async_flow():
await print_values([1, 2]) # runs immediately
coros = [print_values("abcd"), print_values("6789")]
# asynchronously gather the tasks
await asyncio.gather(*coros)
asyncio.run(async_flow()) # ERROR: Awaitable[None] is incompatible with Coroutine[Any, Any, _T@run]
It appears that the issue is coming from one of the type overloads of Flow.__call__
:
@overload
def __call__(
self: "Flow[P, Coroutine[Any, Any, T]]", *args: P.args, **kwargs: P.kwargs
) -> Awaitable[T]:
...
Since the generic Flow
type indicates that we are wrapping a Coroutine
, which derives from an Awaitable
, I thought it would be useful to avoid a potential Liskov substitution violation and return a Coroutine[Any, Any, T]
.