mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
bpo-32703: Fix coroutine resource warning in case where there's an error (GH-5410)
The commit removes one unnecessary "if" clause in genobject.c. That "if" clause was masking un-awaited coroutines warnings just to make writing unittests more convenient.
This commit is contained in:
parent
b647d7039d
commit
2a2270db9b
3 changed files with 73 additions and 40 deletions
|
|
@ -44,9 +44,10 @@ _PyGen_Finalize(PyObject *self)
|
|||
PyObject *res = NULL;
|
||||
PyObject *error_type, *error_value, *error_traceback;
|
||||
|
||||
if (gen->gi_frame == NULL || gen->gi_frame->f_stacktop == NULL)
|
||||
if (gen->gi_frame == NULL || gen->gi_frame->f_stacktop == NULL) {
|
||||
/* Generator isn't paused, so no need to close */
|
||||
return;
|
||||
}
|
||||
|
||||
if (PyAsyncGen_CheckExact(self)) {
|
||||
PyAsyncGenObject *agen = (PyAsyncGenObject*)self;
|
||||
|
|
@ -75,18 +76,18 @@ _PyGen_Finalize(PyObject *self)
|
|||
issue a RuntimeWarning. */
|
||||
if (gen->gi_code != NULL &&
|
||||
((PyCodeObject *)gen->gi_code)->co_flags & CO_COROUTINE &&
|
||||
gen->gi_frame->f_lasti == -1) {
|
||||
if (!error_value) {
|
||||
_PyErr_WarnUnawaitedCoroutine((PyObject *)gen);
|
||||
}
|
||||
gen->gi_frame->f_lasti == -1)
|
||||
{
|
||||
_PyErr_WarnUnawaitedCoroutine((PyObject *)gen);
|
||||
}
|
||||
else {
|
||||
res = gen_close(gen, NULL);
|
||||
}
|
||||
|
||||
if (res == NULL) {
|
||||
if (PyErr_Occurred())
|
||||
if (PyErr_Occurred()) {
|
||||
PyErr_WriteUnraisable(self);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Py_DECREF(res);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue