]> granicus.if.org Git - python/commitdiff
Don't hide unexpected errors in PyErr_WarnExplicitObject(). (GH-4585) (#4662)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 1 Dec 2017 07:21:45 +0000 (23:21 -0800)
committerSerhiy Storchaka <storchaka@gmail.com>
Fri, 1 Dec 2017 07:21:45 +0000 (09:21 +0200)
(cherry picked from commit a561862048555d555fa4850eaf832ae5474c7e1f)

Python/ast.c

index d2710259acb723959906bdb03e9354b1e5f93158..ede7f4fd990ca73e2cd24e88a39ede3a2450e03c 100644 (file)
@@ -4136,18 +4136,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;