cpython: b7b73029c825 (original) (raw)
Mercurial > cpython
changeset 96410:b7b73029c825 3.4
Issue 24004: Support Awaitables (pep 492) in @asyncio.coroutine decorator
Yury Selivanov yselivanov@sprymix.com | |
---|---|
date | Sat, 30 May 2015 21:02:12 -0400 |
parents | 943fa0e8b6a4 |
children | d1959cafc68c 0708aabefb55 |
files | Lib/asyncio/coroutines.py |
diffstat | 1 files changed, 13 insertions(+), 2 deletions(-)[+] [-] Lib/asyncio/coroutines.py 15 |
line wrap: on
line diff
--- a/Lib/asyncio/coroutines.py +++ b/Lib/asyncio/coroutines.py @@ -54,9 +54,10 @@ else: inspect.CO_COROUTINE) try:
- from collections.abc import Coroutine as CoroutineABC, [](#l1.8)
Awaitable as AwaitableABC[](#l1.9)
Check for CPython issue #21209
@@ -192,6 +193,16 @@ def coroutine(func): res = func(*args, **kw) if isinstance(res, futures.Future) or inspect.isgenerator(res): res = yield from res
elif AwaitableABC is not None:[](#l1.20)
# If 'func' returns an Awaitable (new in 3.5) we[](#l1.21)
# want to run it.[](#l1.22)
try:[](#l1.23)
await_meth = res.__await__[](#l1.24)
except AttributeError:[](#l1.25)
pass[](#l1.26)
else:[](#l1.27)
if isinstance(res, AwaitableABC):[](#l1.28)
res = yield from await_meth()[](#l1.29) return res[](#l1.30)