[issue24004] avoid explicit generator type check in asyncio

Stefan Behnel report at bugs.python.org
Sat May 30 11:26:32 CEST 2015


Stefan Behnel added the comment:

I found one more place in asyncio.coroutines, around line 190 in the coroutine() decorator:

    if inspect.isgeneratorfunction(func):
        coro = func
    else:
        @functools.wraps(func)
        def coro(*args, **kw):
            res = func(*args, **kw)
            if isinstance(res, futures.Future) or inspect.isgenerator(res):
                res = yield from res
            return res

The wrapped isgenerator() check should be replaced by an Awaitable ABC check, e.g. this works for me:

"""
             res = func(*args, **kw)
             if isinstance(res, futures.Future) or inspect.isgenerator(res):
                 res = yield from res
+            else:
+                await_res =  getattr(res, '__await__', None)
+                if await_res is not None:
+                    res = yield from await_res()
             return res
"""

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24004>
_______________________________________


More information about the Python-bugs-list mailing list