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:
Yury Selivanov 2018-01-29 14:31:47 -05:00 committed by GitHub
parent b647d7039d
commit 2a2270db9b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 73 additions and 40 deletions

View file

@ -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);