summaryrefslogtreecommitdiffstats
path: root/Modules/_asynciomodule.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/_asynciomodule.c')
-rw-r--r--Modules/_asynciomodule.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c
index b929e6d..c1aa849 100644
--- a/Modules/_asynciomodule.c
+++ b/Modules/_asynciomodule.c
@@ -597,12 +597,27 @@ future_set_exception(asyncio_state *state, FutureObj *fut, PyObject *exc)
PyErr_SetString(PyExc_TypeError, "invalid exception object");
return NULL;
}
- if (Py_IS_TYPE(exc_val, (PyTypeObject *)PyExc_StopIteration)) {
+ if (PyErr_GivenExceptionMatches(exc_val, PyExc_StopIteration)) {
+ const char *msg = "StopIteration interacts badly with "
+ "generators and cannot be raised into a "
+ "Future";
+ PyObject *message = PyUnicode_FromString(msg);
+ if (message == NULL) {
+ Py_DECREF(exc_val);
+ return NULL;
+ }
+ PyObject *err = PyObject_CallOneArg(PyExc_RuntimeError, message);
+ Py_DECREF(message);
+ if (err == NULL) {
+ Py_DECREF(exc_val);
+ return NULL;
+ }
+ assert(PyExceptionInstance_Check(err));
+
+ PyException_SetCause(err, Py_NewRef(exc_val));
+ PyException_SetContext(err, Py_NewRef(exc_val));
Py_DECREF(exc_val);
- PyErr_SetString(PyExc_TypeError,
- "StopIteration interacts badly with generators "
- "and cannot be raised into a Future");
- return NULL;
+ exc_val = err;
}
assert(!fut->fut_exception);