[Python-checkins] cpython (merge 3.5 -> default): Merge 3.5 (issue #25647)

yury.selivanov python-checkins at python.org
Wed Mar 2 10:49:40 EST 2016


https://hg.python.org/cpython/rev/e3aee2f16937
changeset:   100393:e3aee2f16937
parent:      100391:a56045022a09
parent:      100392:fd21f162e377
user:        Yury Selivanov <yselivanov at sprymix.com>
date:        Wed Mar 02 10:49:36 2016 -0500
summary:
  Merge 3.5 (issue #25647)

files:
  Lib/asyncio/coroutines.py           |   3 +-
  Lib/test/test_asyncio/test_tasks.py |  24 +++++++++++++++++
  2 files changed, 26 insertions(+), 1 deletions(-)


diff --git a/Lib/asyncio/coroutines.py b/Lib/asyncio/coroutines.py
--- a/Lib/asyncio/coroutines.py
+++ b/Lib/asyncio/coroutines.py
@@ -204,7 +204,8 @@
         @functools.wraps(func)
         def coro(*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
             elif _AwaitableABC is not None:
                 # If 'func' returns an Awaitable (new in 3.5) we
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py
--- a/Lib/test/test_asyncio/test_tasks.py
+++ b/Lib/test/test_asyncio/test_tasks.py
@@ -1794,6 +1794,30 @@
 
         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):
         self.loop.set_debug(True)
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list