mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
GH-96793: Implement PEP 479 in bytecode. (GH-99006)
* Handle converting StopIteration to RuntimeError in bytecode. * Add custom instruction for converting StopIteration into RuntimeError.
This commit is contained in:
parent
e9ac890c02
commit
f4adb97506
14 changed files with 220 additions and 96 deletions
|
@ -246,25 +246,9 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult,
|
|||
}
|
||||
}
|
||||
else {
|
||||
if (PyErr_ExceptionMatches(PyExc_StopIteration)) {
|
||||
const char *msg = "generator raised StopIteration";
|
||||
if (PyCoro_CheckExact(gen)) {
|
||||
msg = "coroutine raised StopIteration";
|
||||
}
|
||||
else if (PyAsyncGen_CheckExact(gen)) {
|
||||
msg = "async generator raised StopIteration";
|
||||
}
|
||||
_PyErr_FormatFromCause(PyExc_RuntimeError, "%s", msg);
|
||||
}
|
||||
else if (PyAsyncGen_CheckExact(gen) &&
|
||||
PyErr_ExceptionMatches(PyExc_StopAsyncIteration))
|
||||
{
|
||||
/* code in `gen` raised a StopAsyncIteration error:
|
||||
raise a RuntimeError.
|
||||
*/
|
||||
const char *msg = "async generator raised StopAsyncIteration";
|
||||
_PyErr_FormatFromCause(PyExc_RuntimeError, "%s", msg);
|
||||
}
|
||||
assert(!PyErr_ExceptionMatches(PyExc_StopIteration));
|
||||
assert(!PyAsyncGen_CheckExact(gen) ||
|
||||
!PyErr_ExceptionMatches(PyExc_StopAsyncIteration));
|
||||
}
|
||||
|
||||
/* generator can't be rerun, so release the frame */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue