diff -r be66786e95de Python/ast.c --- a/Python/ast.c Mon Nov 14 12:38:43 2016 +0100 +++ b/Python/ast.c Mon Nov 14 18:04:13 2016 +0100 @@ -4129,7 +4129,13 @@ warn_invalid_escape_sequence(struct comp 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); }