Don't hide unexpected errors in PyErr_WarnExplicitObject(). (GH-4585) (#4662)

(cherry picked from commit a561862048)
This commit is contained in:
Miss Islington (bot) 2017-11-30 23:21:45 -08:00 committed by Serhiy Storchaka
parent 8bcd41040a
commit 9881e4e538

View file

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