From fb5a7ad421ac20c49218ee4b86fb0d85ca4cd664 Mon Sep 17 00:00:00 2001 From: "Nathaniel J. Smith" Date: Wed, 24 Jan 2018 12:14:33 -0800 Subject: [PATCH] bpo-32636: Fix @asyncio.coroutine debug mode bug exposed by gh-5250 (#5291) --- Lib/asyncio/coroutines.py | 3 ++- Lib/test/test_asyncio/test_tasks.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Lib/asyncio/coroutines.py b/Lib/asyncio/coroutines.py index 5a29100321..c7fcd44255 100644 --- a/Lib/asyncio/coroutines.py +++ b/Lib/asyncio/coroutines.py @@ -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): diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py index daa1ff927e..5e83a54ff2 100644 --- a/Lib/test/test_asyncio/test_tasks.py +++ b/Lib/test/test_asyncio/test_tasks.py @@ -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() -- 2.40.0