]> 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 19:53:07 +0000 (15:53 -0400)
committerGitHub <noreply@github.com>
Sun, 12 Mar 2017 19:53:07 +0000 (15:53 -0400)
Lib/test/test_coroutines.py
Objects/genobject.c

index b4c7b5be6e208c79d040f3a5034d217cd2edf1ae..a69583b5f95ae69a1763e79acd9fdcd721f15bce 100644 (file)
@@ -1103,6 +1103,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 24a1da6f3e5c8cd27158e28a5df3e368f5047148..8c2213e5bf229aac5a993c1df11ad85ba6900b93 100644 (file)
@@ -574,8 +574,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);