diff options
author | Yury Selivanov <yselivanov@sprymix.com> | 2015-05-31 01:02:34 (GMT) |
---|---|---|
committer | Yury Selivanov <yselivanov@sprymix.com> | 2015-05-31 01:02:34 (GMT) |
commit | 353f2299bf1f5dc8483fcdca3689469a7079d4a1 (patch) | |
tree | 47f98d9a957e801ba926fae4a0638dac61ea8710 /Lib/asyncio | |
parent | bf304fcb3255d6fe52f83c120feccdf64f5a9715 (diff) | |
parent | a316085192382e56c8322da395231e24c6dbdc5b (diff) | |
download | cpython-353f2299bf1f5dc8483fcdca3689469a7079d4a1.zip cpython-353f2299bf1f5dc8483fcdca3689469a7079d4a1.tar.gz cpython-353f2299bf1f5dc8483fcdca3689469a7079d4a1.tar.bz2 |
Issue 24004: Support Awaitables (pep 492) in @asyncio.coroutine decorator
(Merge 3.4)
Diffstat (limited to 'Lib/asyncio')
-rw-r--r-- | Lib/asyncio/coroutines.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/Lib/asyncio/coroutines.py b/Lib/asyncio/coroutines.py index 1e0a704..4933cf8 100644 --- 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 + from collections.abc import Coroutine as CoroutineABC, \ + Awaitable as AwaitableABC except ImportError: - CoroutineABC = None + CoroutineABC = AwaitableABC = None # 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: + # If 'func' returns an Awaitable (new in 3.5) we + # want to run it. + try: + await_meth = res.__await__ + except AttributeError: + pass + else: + if isinstance(res, AwaitableABC): + res = yield from await_meth() return res if not _DEBUG: |