]> granicus.if.org Git - python/commitdiff
Fix wrapping into StopIteration of return values in generators and coroutines (#644...
authorYury Selivanov <yselivanov@gmail.com>
Sun, 12 Mar 2017 21:03:46 +0000 (17:03 -0400)
committerGitHub <noreply@github.com>
Sun, 12 Mar 2017 21:03:46 +0000 (17:03 -0400)
Lib/test/test_coroutines.py
Misc/NEWS
Objects/genobject.c

index 4a327b5ba9f16835e6a0de313ebcf461bb153b0a..6d63cdb5f0fcc929009b9c4eaddbe9a8e2d7d584 100644 (file)
@@ -975,6 +975,21 @@ class CoroutineTest(unittest.TestCase):
                                     "coroutine is being awaited already"):
             waiter(coro).send(None)
 
+    def test_await_16(self):
+        # See https://bugs.python.org/issue29600 for details.
+
+        async def f():
+            return ValueError()
+
+        async def g():
+            try:
+                raise KeyError
+            except:
+                return await f()
+
+        _, result = run_async(g())
+        self.assertIsNone(result.__context__)
+
     def test_with_1(self):
         class Manager:
             def __init__(self, name):
index 98b47bdab4a8f111e825c1d9d25dd93a97becc49..e56c0914b1b8d276003272db38335ecd317f956d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@ Release date: XXXX-XX-XX
 Core and Builtins
 -----------------
 
+- bpo-29600: Fix wrapping coroutine return values in StopIteration.
+
 - Issue #29537: Restore runtime compatibility with bytecode files generated by
   CPython 3.5.0 to 3.5.2, and adjust the eval loop to avoid the problems that
   could be caused by the malformed variant of the BUILD_MAP_UNPACK_WITH_CALL
index d403598181abd4c85facb9afd624b08168847004..0de540898d5e15276aea8b1d302349b3630033ce 100644 (file)
@@ -466,8 +466,7 @@ _PyGen_SetStopIterationValue(PyObject *value)
     PyObject *e;
 
     if (value == NULL ||
-        (!PyTuple_Check(value) &&
-         !PyObject_TypeCheck(value, (PyTypeObject *) PyExc_StopIteration)))
+        (!PyTuple_Check(value) && !PyExceptionInstance_Check(value)))
     {
         /* Delay exception instantiation if we can */
         PyErr_SetObject(PyExc_StopIteration, value);