summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-11-15 08:12:36 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-11-15 08:12:36 (GMT)
commitd5f599a39270b4fd791f7e0190bede9911bb0e52 (patch)
treecc60c07976aa6eb1b180427c2a8bacc878efc7db
parent9ee351fc1ee318199931028b8bcfff4954dd01f5 (diff)
parentf9cca365c72eaa932f1bee6407fbbbc3b4ed96f0 (diff)
downloadcpython-d5f599a39270b4fd791f7e0190bede9911bb0e52.zip
cpython-d5f599a39270b4fd791f7e0190bede9911bb0e52.tar.gz
cpython-d5f599a39270b4fd791f7e0190bede9911bb0e52.tar.bz2
Merge 3.6
-rw-r--r--Lib/test/test_string_literals.py20
-rw-r--r--Python/ast.c8
2 files changed, 27 insertions, 1 deletions
diff --git a/Lib/test/test_string_literals.py b/Lib/test/test_string_literals.py
index 54f2be3..aba4fc4 100644
--- a/Lib/test/test_string_literals.py
+++ b/Lib/test/test_string_literals.py
@@ -111,6 +111,7 @@ class TestLiterals(unittest.TestCase):
continue
with self.assertWarns(DeprecationWarning):
self.assertEqual(eval(r"'\%c'" % b), '\\' + chr(b))
+
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always', category=DeprecationWarning)
eval("'''\n\\z'''")
@@ -118,6 +119,15 @@ class TestLiterals(unittest.TestCase):
self.assertEqual(w[0].filename, '<string>')
self.assertEqual(w[0].lineno, 2)
+ with warnings.catch_warnings(record=True) as w:
+ warnings.simplefilter('error', category=DeprecationWarning)
+ with self.assertRaises(SyntaxError) as cm:
+ eval("'''\n\\z'''")
+ exc = cm.exception
+ self.assertEqual(w, [])
+ self.assertEqual(exc.filename, '<string>')
+ self.assertEqual(exc.lineno, 2)
+
def test_eval_str_raw(self):
self.assertEqual(eval(""" r'x' """), 'x')
self.assertEqual(eval(r""" r'\x01' """), '\\' + 'x01')
@@ -150,6 +160,7 @@ class TestLiterals(unittest.TestCase):
continue
with self.assertWarns(DeprecationWarning):
self.assertEqual(eval(r"b'\%c'" % b), b'\\' + bytes([b]))
+
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always', category=DeprecationWarning)
eval("b'''\n\\z'''")
@@ -157,6 +168,15 @@ class TestLiterals(unittest.TestCase):
self.assertEqual(w[0].filename, '<string>')
self.assertEqual(w[0].lineno, 2)
+ with warnings.catch_warnings(record=True) as w:
+ warnings.simplefilter('error', category=DeprecationWarning)
+ with self.assertRaises(SyntaxError) as cm:
+ eval("b'''\n\\z'''")
+ exc = cm.exception
+ self.assertEqual(w, [])
+ self.assertEqual(exc.filename, '<string>')
+ self.assertEqual(exc.lineno, 2)
+
def test_eval_bytes_raw(self):
self.assertEqual(eval(""" br'x' """), b'x')
self.assertEqual(eval(""" rb'x' """), b'x')
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);
}