From f9cca365c72eaa932f1bee6407fbbbc3b4ed96f0 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 15 Nov 2016 09:12:10 +0100 Subject: 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. --- Python/ast.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'Python/ast.c') diff --git a/Python/ast.c b/Python/ast.c index bfae6ed7d4..14bcdb1b0a 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -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); } -- cgit v1.2.1