Commit b7c9150b authored by Yury Selivanov's avatar Yury Selivanov Committed by GitHub

Fix wrapping into StopIteration of return values in generators and coroutines (#644)

parent 2b27e2e6
...@@ -1103,6 +1103,21 @@ class CoroutineTest(unittest.TestCase): ...@@ -1103,6 +1103,21 @@ class CoroutineTest(unittest.TestCase):
"coroutine is being awaited already"): "coroutine is being awaited already"):
waiter(coro).send(None) 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): def test_with_1(self):
class Manager: class Manager:
def __init__(self, name): def __init__(self, name):
......
...@@ -574,8 +574,7 @@ _PyGen_SetStopIterationValue(PyObject *value) ...@@ -574,8 +574,7 @@ _PyGen_SetStopIterationValue(PyObject *value)
PyObject *e; PyObject *e;
if (value == NULL || if (value == NULL ||
(!PyTuple_Check(value) && (!PyTuple_Check(value) && !PyExceptionInstance_Check(value)))
!PyObject_TypeCheck(value, (PyTypeObject *) PyExc_StopIteration)))
{ {
/* Delay exception instantiation if we can */ /* Delay exception instantiation if we can */
PyErr_SetObject(PyExc_StopIteration, value); PyErr_SetObject(PyExc_StopIteration, value);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment