async def
returns a coroutine object: import asyncio async def coro_func(): pass coro_obj = coro_func() print(type(coro_obj)) # <class 'coroutine'> asyncio.run(coro_obj)
async def
functions are always coroutines, even if they do not contain await
expressions.
SyntaxError
to have yield
or yield from
expressions in an async
function.
CO_COROUTINE
is used to mark native coroutines (defined with new syntax); O_ITERABLE_COROUTINE
is used to make generator-based coroutines compatible with native coroutines (set by types.coroutine()
function).
StopIteration
exceptions are not propagated out of coroutines, and are replaced with a RuntimeError
. For regular generators such behavior requires a future import (see PEP 479).
RuntimeWarning
is raised if it was never awaited on. import asyncio async def coro(): pass coro()