Hey!

In APIs that take a coroutine callbacks as a parameter, one would like to 
make sure the callback given is in fact a coroutine. Partials are of course 
useful in this scenario.
It occurs to me that `asyncio.iscoroutinefunction` should know about 
coroutines wrapped in partials:

>>> import asyncio
>>> import functools
>>> @asyncio.coroutine
... def myfunc():
...     pass
...
>>> part = functools.partial(myfunc)
>>> asyncio.iscoroutinefunction(myfunc)
True
>>> asyncio.iscoroutinefunction(part)
False
>>>

Here's a naive workaround:

def iscoroutinefunction(func):
    if asyncio.iscoroutinefunction(func):
        return True
    
    return asyncio.iscoroutinefunction(getattr(func, 'func', None))


What do you think?

Best regards
Ron Cohen
CTO & co-founder @ Opbeat

Reply via email to