Stefan Behnel added the comment:
Regarding the patch below, isn't most of this redundant? ISTM that simply
calling PyErr_SetString(...) should do all of this, including the exception
chaining.
diff -r 23ab1197df0b Objects/genobject.c
--- a/Objects/genobject.c Wed Nov 19 13:21:40 2014 +0200
+++ b/Objects/genobject.c Thu Nov 20 16:47:59 2014 +1100
@@ -130,6 +130,23 @@
}
Py_CLEAR(result);
}
+ else if (!result)
+ {
+ if (PyErr_ExceptionMatches(PyExc_StopIteration))
+ {
+ PyObject *exc, *val, *val2, *tb;
+ PyErr_Fetch(&exc, &val, &tb);
+ PyErr_NormalizeException(&exc, &val, &tb);
+ Py_DECREF(exc);
+ Py_XDECREF(tb);
+ PyErr_SetString(PyExc_RuntimeError,
+ "generator raised StopIteration");
+ PyErr_Fetch(&exc, &val2, &tb);
+ PyErr_NormalizeException(&exc, &val2, &tb);
+ PyException_SetContext(val2, val);
+ PyErr_Restore(exc, val2, tb);
+ }
+ }
if (!result || f->f_stacktop == NULL) {
/* generator can't be rerun, so release the frame */
----------
nosy: +scoder
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue22906>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com