summaryrefslogtreecommitdiff
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-11-15 09:12:10 +0100
committerVictor Stinner <victor.stinner@gmail.com>2016-11-15 09:12:10 +0100
commitda22e7f2daa3cdcae574441f05526e8231a8ad3b (patch)
tree9b1613808a221708353147c053359d7f80e4a67f /Python
parent109c5479d5dd1ad9fc68484f81b5e27e05b25abc (diff)
downloadcpython-da22e7f2daa3cdcae574441f05526e8231a8ad3b.tar.gz
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.
Diffstat (limited to 'Python')
-rw-r--r--Python/ast.c8
1 files changed, 7 insertions, 1 deletions
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);
}