]> granicus.if.org Git - python/commitdiff
Don't hide unexpected errors in PyErr_WarnExplicitObject(). (#4585)
authorSerhiy Storchaka <storchaka@gmail.com>
Fri, 1 Dec 2017 06:40:23 +0000 (08:40 +0200)
committerGitHub <noreply@github.com>
Fri, 1 Dec 2017 06:40:23 +0000 (08:40 +0200)
Python/ast.c

index e44ce516617a682fc7c03daa842c502afdae9ccf..e2092f0f85433e95cc690b03cc5399b448f61d81 100644 (file)
@@ -4160,18 +4160,19 @@ warn_invalid_escape_sequence(struct compiling *c, const node *n,
     }
     if (PyErr_WarnExplicitObject(PyExc_DeprecationWarning, msg,
                                    c->c_filename, LINENO(n),
-                                   NULL, NULL) < 0 &&
-        PyErr_ExceptionMatches(PyExc_DeprecationWarning))
+                                   NULL, NULL) < 0)
     {
-        const char *s;
+        if (PyErr_ExceptionMatches(PyExc_DeprecationWarning)) {
+            const char *s;
 
-        /* Replace the DeprecationWarning exception with a SyntaxError
-           to get a more accurate error report */
-        PyErr_Clear();
+            /* Replace the DeprecationWarning exception with a SyntaxError
+               to get a more accurate error report */
+            PyErr_Clear();
 
-        s = PyUnicode_AsUTF8(msg);
-        if (s != NULL) {
-            ast_error(c, n, s);
+            s = PyUnicode_AsUTF8(msg);
+            if (s != NULL) {
+                ast_error(c, n, s);
+            }
         }
         Py_DECREF(msg);
         return -1;