Skip to content

asyncio.Runner explicitly checks for coroutine #120284

@ronf

Description

@ronf

The class asyncio.Runner currently checks explicitly that its coro argument is a coroutine:

"""Run a coroutine inside the embedded event loop."""
if not coroutines.iscoroutine(coro):
raise ValueError("a coroutine was expected, got {!r}".format(coro))

However, shouldn't this allow any awaitable, checked via inspect.isawaitable(), or perhaps aligned with run_until_complete(), which currently accepts a Future object? Is there a specific reason why only coroutines are allowed here?

I've got a class which implements a custom __await__() method that I'd like to be able to pass into asyncio.Runner, but the check above is preventing this. There are workaround for this, like wrapping the await on the object in a regular async function, but I'd prefer not to require that.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions