]> granicus.if.org Git - python/commitdiff
bpo-32636: Fix @asyncio.coroutine debug mode bug exposed by gh-5250 (#5291)
authorNathaniel J. Smith <njs@pobox.com>
Wed, 24 Jan 2018 20:14:33 +0000 (12:14 -0800)
committerYury Selivanov <yury@magic.io>
Wed, 24 Jan 2018 20:14:33 +0000 (15:14 -0500)
Lib/asyncio/coroutines.py
Lib/test/test_asyncio/test_tasks.py

index 5a29100321fae97b7030950c7c5efa37d7984886..c7fcd4425584806eb373f276de979768d9f62898 100644 (file)
@@ -132,8 +132,9 @@ def coroutine(func):
                         res = yield from await_meth()
             return res
 
+    coro = types.coroutine(coro)
     if not _DEBUG:
-        wrapper = types.coroutine(coro)
+        wrapper = coro
     else:
         @functools.wraps(func)
         def wrapper(*args, **kwds):
index daa1ff927e6d09dd12f96f908a5d13f6bb95f97c..5e83a54ff28c85c4a72168cf4fd76dc5ab2c1aec 100644 (file)
@@ -9,6 +9,7 @@ import io
 import random
 import re
 import sys
+import textwrap
 import types
 import unittest
 import weakref
@@ -3090,6 +3091,22 @@ class CompatibilityTests(test_utils.TestCase):
         result = self.loop.run_until_complete(inner())
         self.assertEqual(['ok1', 'ok2'], result)
 
+    def test_debug_mode_interop(self):
+        # https://bugs.python.org/issue32636
+        code = textwrap.dedent("""
+            import asyncio
+
+            async def native_coro():
+                pass
+
+            @asyncio.coroutine
+            def old_style_coro():
+                yield from native_coro()
+
+            asyncio.run(old_style_coro())
+        """)
+        assert_python_ok("-c", code, PYTHONASYNCIODEBUG="1")
+
 
 if __name__ == '__main__':
     unittest.main()