Fix warn_invalid_escape_sequence()

Issue #28691: Fix warn_invalid_escape_sequence(): handle correctly
DeprecationWarning raised as an exception. First clear the current exception to
replace the DeprecationWarning exception with a SyntaxError exception.

Unit test written by Serhiy Storchaka.
This commit is contained in:
Victor Stinner 2016-11-15 09:12:10 +01:00
parent de40e1218c
commit f9cca365c7
2 changed files with 27 additions and 1 deletions

View file

@ -4129,7 +4129,13 @@ warn_invalid_escape_sequence(struct compiling *c, const node *n,
NULL, NULL) < 0 &&
PyErr_ExceptionMatches(PyExc_DeprecationWarning))
{
const char *s = PyUnicode_AsUTF8(msg);
const char *s;
/* 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);
}