Open
Description
It would be nice to be able to use this with asyncio methods like run
and create_task
without needing to resort to escape hatches like typing.cast
or #type: ignore
. I'm not sure that is just having a result.as_coroutine_result
or there's a better way.
An example case is the following:
from result import as_async_result
import random
import asyncio
@as_async_result(Exception)
async def example() -> str:
if random.random() < 0.5:
raise RuntimeError("Boom")
return "made it"
task: str = asyncio.run( example() )
print(task)
Running mypy
on that will produce the following error:
error: Argument 1 to "run" has incompatible type "Awaitable[Ok[str] | Err[Exception]]"; expected "Coroutine[Any, Any, Never]"
Metadata
Assignees
Labels
No labels