mirror of
https://github.com/python/cpython.git
synced 2025-08-27 20:25:18 +00:00
asyncio: Fix @coroutine to recognize CoroWrapper (issue #25647)
Patch by Vladimir Rutsky.
This commit is contained in:
parent
0c6a34409e
commit
dce63234c5
2 changed files with 26 additions and 1 deletions
|
@ -204,7 +204,8 @@ def coroutine(func):
|
||||||
@functools.wraps(func)
|
@functools.wraps(func)
|
||||||
def coro(*args, **kw):
|
def coro(*args, **kw):
|
||||||
res = func(*args, **kw)
|
res = func(*args, **kw)
|
||||||
if isinstance(res, futures.Future) or inspect.isgenerator(res):
|
if isinstance(res, futures.Future) or inspect.isgenerator(res) or \
|
||||||
|
isinstance(res, CoroWrapper):
|
||||||
res = yield from res
|
res = yield from res
|
||||||
elif _AwaitableABC is not None:
|
elif _AwaitableABC is not None:
|
||||||
# If 'func' returns an Awaitable (new in 3.5) we
|
# If 'func' returns an Awaitable (new in 3.5) we
|
||||||
|
|
|
@ -1794,6 +1794,30 @@ class TaskTests(test_utils.TestCase):
|
||||||
|
|
||||||
self.assertRegex(message, re.compile(regex, re.DOTALL))
|
self.assertRegex(message, re.compile(regex, re.DOTALL))
|
||||||
|
|
||||||
|
def test_return_coroutine_from_coroutine(self):
|
||||||
|
"""Return of @asyncio.coroutine()-wrapped function generator object
|
||||||
|
from @asyncio.coroutine()-wrapped function should have same effect as
|
||||||
|
returning generator object or Future."""
|
||||||
|
def check():
|
||||||
|
@asyncio.coroutine
|
||||||
|
def outer_coro():
|
||||||
|
@asyncio.coroutine
|
||||||
|
def inner_coro():
|
||||||
|
return 1
|
||||||
|
|
||||||
|
return inner_coro()
|
||||||
|
|
||||||
|
result = self.loop.run_until_complete(outer_coro())
|
||||||
|
self.assertEqual(result, 1)
|
||||||
|
|
||||||
|
# Test with debug flag cleared.
|
||||||
|
with set_coroutine_debug(False):
|
||||||
|
check()
|
||||||
|
|
||||||
|
# Test with debug flag set.
|
||||||
|
with set_coroutine_debug(True):
|
||||||
|
check()
|
||||||
|
|
||||||
def test_task_source_traceback(self):
|
def test_task_source_traceback(self):
|
||||||
self.loop.set_debug(True)
|
self.loop.set_debug(True)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue