mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
do not allow _PyGen_Finalize to fail (closes #27811)
Patch from Armin Rigo.
This commit is contained in:
parent
fb5ce7eea1
commit
2f40ed4b94
3 changed files with 25 additions and 13 deletions
|
@ -24,18 +24,6 @@ _PyGen_Finalize(PyObject *self)
|
|||
PyObject *res;
|
||||
PyObject *error_type, *error_value, *error_traceback;
|
||||
|
||||
/* If `gen` is a coroutine, and if it was never awaited on,
|
||||
issue a RuntimeWarning. */
|
||||
if (gen->gi_code != NULL
|
||||
&& ((PyCodeObject *)gen->gi_code)->co_flags & CO_COROUTINE
|
||||
&& gen->gi_frame != NULL
|
||||
&& gen->gi_frame->f_lasti == -1
|
||||
&& !PyErr_Occurred()
|
||||
&& PyErr_WarnFormat(PyExc_RuntimeWarning, 1,
|
||||
"coroutine '%.50S' was never awaited",
|
||||
gen->gi_qualname))
|
||||
return;
|
||||
|
||||
if (gen->gi_frame == NULL || gen->gi_frame->f_stacktop == NULL)
|
||||
/* Generator isn't paused, so no need to close */
|
||||
return;
|
||||
|
@ -43,7 +31,20 @@ _PyGen_Finalize(PyObject *self)
|
|||
/* Save the current exception, if any. */
|
||||
PyErr_Fetch(&error_type, &error_value, &error_traceback);
|
||||
|
||||
res = gen_close(gen, NULL);
|
||||
/* If `gen` is a coroutine, and if it was never awaited on,
|
||||
issue a RuntimeWarning. */
|
||||
if (gen->gi_code != NULL
|
||||
&& ((PyCodeObject *)gen->gi_code)->co_flags & CO_COROUTINE
|
||||
&& gen->gi_frame->f_lasti == -1
|
||||
&& !PyErr_Occurred()
|
||||
&& PyErr_WarnFormat(PyExc_RuntimeWarning, 1,
|
||||
"coroutine '%.50S' was never awaited",
|
||||
gen->gi_qualname)) {
|
||||
res = NULL; /* oops, exception */
|
||||
}
|
||||
else {
|
||||
res = gen_close(gen, NULL);
|
||||
}
|
||||
|
||||
if (res == NULL)
|
||||
PyErr_WriteUnraisable(self);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue