summaryrefslogtreecommitdiffstats
path: root/Python/ast.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-11-15 08:12:10 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-11-15 08:12:10 (GMT)
commitf9cca365c72eaa932f1bee6407fbbbc3b4ed96f0 (patch)
tree12858858baf93a9b88cc36aa9c938595df28d025 /Python/ast.c
parentde40e1218c8dff29ee9de634034e3ed7b3979c86 (diff)
downloadcpython-f9cca365c72eaa932f1bee6407fbbbc3b4ed96f0.zip
cpython-f9cca365c72eaa932f1bee6407fbbbc3b4ed96f0.tar.gz
cpython-f9cca365c72eaa932f1bee6407fbbbc3b4ed96f0.tar.bz2
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/ast.c')
-rw-r--r--Python/ast.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/Python/ast.c b/Python/ast.c
index bfae6ed..14bcdb1 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);
}