[Python-Dev] cpython (3.5): supress coroutine warning when an exception is pending (#27968) (original) (raw)

Benjamin Peterson benjamin at python.org
Thu Sep 8 11:38:00 EDT 2016


On Thu, Sep 8, 2016, at 04:09, Christian Heimes wrote:

On 2016-09-07 17:47, benjamin.peterson wrote: > https://hg.python.org/cpython/rev/234f758449f8 > changeset: 103223:234f758449f8 > branch: 3.5 > parent: 103213:7537ca1c2aaf > user: Benjamin Peterson <benjamin at python.org> > date: Wed Sep 07 08:46:59 2016 -0700 > summary: > supress coroutine warning when an exception is pending (#27968) > > files: > Objects/genobject.c | 27 +++++++++++++++------------ > 1 files changed, 15 insertions(+), 12 deletions(-) > > > diff --git a/Objects/genobject.c b/Objects/genobject.c > --- a/Objects/genobject.c > +++ b/Objects/genobject.c > @@ -21,7 +21,7 @@ > PyGenFinalize(PyObject *self) > { > PyGenObject *gen = (PyGenObject *)self; > - PyObject *res; > + PyObject *res = NULL; > PyObject *errortype, *errorvalue, *errortraceback; > > if (gen->giframe == NULL || gen->giframe->fstacktop == NULL) > @@ -33,23 +33,26 @@ > > /* If gen is a coroutine, and if it was never awaited on, > issue a RuntimeWarning. */ > - if (gen->gicode != NULL > - && ((PyCodeObject *)gen->gicode)->coflags & COCOROUTINE > - && gen->giframe->flasti == -1 > - && !PyErrOccurred() > - && PyErrWarnFormat(PyExcRuntimeWarning, 1, > - "coroutine '%.50S' was never awaited", > - gen->giqualname)) { > - res = NULL; /* oops, exception */ > + if (gen->gicode != NULL && > + ((PyCodeObject *)gen->gicode)->coflags & COCOROUTINE && > + gen->giframe->flasti == -1) { > + if (!errorvalue) { > + PyErrWarnFormat(PyExcRuntimeWarning, 1, > + "coroutine '%.50S' was never awaited", > + gen->giqualname); > + }

You don't check the return value of PyErrWarnFormat(). It does not signal an exception in case warnings are turned into exceptions.

It's checked by PyErr_Occurred() several lines later.



More information about the Python-Dev mailing list