]> granicus.if.org Git - python/commitdiff
bpo-32591: Fix PyExc_WarnFormat call (follow-up commit) (#5263)
authorYury Selivanov <yury@magic.io>
Mon, 22 Jan 2018 01:47:04 +0000 (20:47 -0500)
committerGitHub <noreply@github.com>
Mon, 22 Jan 2018 01:47:04 +0000 (20:47 -0500)
The previous version was correct in terms of behaviour, but
checking the return value of PyErr_WarnFormat allows to
avoid calling PyErr_Occurred and silences the coverity alarm.

Python/_warnings.c

index c3417cccb179d27e20f6502c726a9a3a3163305d..20ba7a16616fe485334fe5057598a1bf372c4314 100644 (file)
@@ -1191,11 +1191,10 @@ _PyErr_WarnUnawaitedCoroutine(PyObject *coro)
         PyErr_WriteUnraisable(coro);
     }
     if (!warned) {
-        PyErr_WarnFormat(PyExc_RuntimeWarning, 1,
-                         "coroutine '%.50S' was never awaited",
-                         ((PyCoroObject *)coro)->cr_qualname);
-        /* Maybe *that* got converted into an exception */
-        if (PyErr_Occurred()) {
+        if (PyErr_WarnFormat(PyExc_RuntimeWarning, 1,
+                             "coroutine '%.50S' was never awaited",
+                             ((PyCoroObject *)coro)->cr_qualname) < 0)
+        {
             PyErr_WriteUnraisable(coro);
         }
     }