Quote from here:
types.CoroutineType
The type of coroutine objects, created by async def functions.
Quote f
g
by itself is not a valid Coroutine function when used that way:
isinstance(g, types.CoroutineType)
This is similar to the difference between a generator and a generator function. Instead, use g()
to compare:
isinstance(g(), types.CoroutineType)
You could also try iscoroutinefunction(g)
instead, much more shorter and neater:
from asyncio import iscoroutinefunction
iscoroutinefunction(g) #Return true
Read more here: https://docs.python.org/3/library/asyncio-task.html