mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
GH-90997: Wrap yield from/await in a virtual try/except StopIteration (GH-96010)
This commit is contained in:
parent
2d9f252c0c
commit
5bfb3c372b
11 changed files with 142 additions and 106 deletions
|
@ -2668,6 +2668,9 @@ handle_eval_breaker:
|
|||
}
|
||||
|
||||
TARGET(YIELD_VALUE) {
|
||||
// NOTE: It's important that YIELD_VALUE never raises an exception!
|
||||
// The compiler treats any exception raised here as a failed close()
|
||||
// or throw() call.
|
||||
assert(oparg == STACK_LEVEL());
|
||||
assert(frame->is_entry);
|
||||
PyObject *retval = POP();
|
||||
|
@ -2746,6 +2749,26 @@ handle_eval_breaker:
|
|||
}
|
||||
}
|
||||
|
||||
TARGET(CLEANUP_THROW) {
|
||||
assert(throwflag);
|
||||
PyObject *exc_value = TOP();
|
||||
assert(exc_value && PyExceptionInstance_Check(exc_value));
|
||||
if (PyErr_GivenExceptionMatches(exc_value, PyExc_StopIteration)) {
|
||||
PyObject *value = ((PyStopIterationObject *)exc_value)->value;
|
||||
Py_INCREF(value);
|
||||
Py_DECREF(POP()); // The StopIteration.
|
||||
Py_DECREF(POP()); // The last sent value.
|
||||
Py_DECREF(POP()); // The delegated sub-iterator.
|
||||
PUSH(value);
|
||||
DISPATCH();
|
||||
}
|
||||
Py_INCREF(exc_value);
|
||||
PyObject *exc_type = Py_NewRef(Py_TYPE(exc_value));
|
||||
PyObject *exc_traceback = PyException_GetTraceback(exc_value);
|
||||
_PyErr_Restore(tstate, exc_type, exc_value, exc_traceback);
|
||||
goto exception_unwind;
|
||||
}
|
||||
|
||||
TARGET(LOAD_ASSERTION_ERROR) {
|
||||
PyObject *value = PyExc_AssertionError;
|
||||
Py_INCREF(value);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue