From a49a5ee2a35ce4c97247d6e5b6064df1b8ad4797 Mon Sep 17 00:00:00 2001 From: "Vgr E. Barry" Date: Sat, 24 Feb 2018 09:07:59 -0500 Subject: [PATCH] bpo-32912: Upgrade warning for invalid escape sequences from silent to non-silent --- Lib/test/test_codecs.py | 20 ++++++++++---------- Lib/test/test_fstring.py | 2 +- Lib/test/test_string_literals.py | 12 ++++++------ Objects/bytesobject.c | 2 +- Objects/unicodeobject.c | 2 +- Python/ast.c | 4 ++-- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index a59a5e21358e7b..71bcac49045dfa 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -1210,15 +1210,15 @@ def test_escape(self): for i in range(97, 123): b = bytes([i]) if b not in b'abfnrtvx': - with self.assertWarns(DeprecationWarning): + with self.assertWarns(SyntaxWarning): check(b"\\" + b, b"\\" + b) - with self.assertWarns(DeprecationWarning): + with self.assertWarns(SyntaxWarning): check(b"\\" + b.upper(), b"\\" + b.upper()) - with self.assertWarns(DeprecationWarning): + with self.assertWarns(SyntaxWarning): check(br"\8", b"\\8") - with self.assertWarns(DeprecationWarning): + with self.assertWarns(SyntaxWarning): check(br"\9", b"\\9") - with self.assertWarns(DeprecationWarning): + with self.assertWarns(SyntaxWarning): check(b"\\\xfa", b"\\\xfa") def test_errors(self): @@ -2482,16 +2482,16 @@ def test_escape_decode(self): for i in range(97, 123): b = bytes([i]) if b not in b'abfnrtuvx': - with self.assertWarns(DeprecationWarning): + with self.assertWarns(SyntaxWarning): check(b"\\" + b, "\\" + chr(i)) if b.upper() not in b'UN': - with self.assertWarns(DeprecationWarning): + with self.assertWarns(SyntaxWarning): check(b"\\" + b.upper(), "\\" + chr(i-32)) - with self.assertWarns(DeprecationWarning): + with self.assertWarns(SyntaxWarning): check(br"\8", "\\8") - with self.assertWarns(DeprecationWarning): + with self.assertWarns(SyntaxWarning): check(br"\9", "\\9") - with self.assertWarns(DeprecationWarning): + with self.assertWarns(SyntaxWarning): check(b"\\\xfa", "\\\xfa") def test_decode_errors(self): diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py index 5e7efe25e39ccc..59ac6cb123128f 100644 --- a/Lib/test/test_fstring.py +++ b/Lib/test/test_fstring.py @@ -618,7 +618,7 @@ def test_backslashes_in_string_part(self): self.assertEqual(f'2\x203', '2 3') self.assertEqual(f'\x203', ' 3') - with self.assertWarns(DeprecationWarning): # invalid escape sequence + with self.assertWarns(SyntaxWarning): # invalid escape sequence value = eval(r"f'\{6*7}'") self.assertEqual(value, '\\42') self.assertEqual(f'\\{6*7}', '\\42') diff --git a/Lib/test/test_string_literals.py b/Lib/test/test_string_literals.py index aba4fc46676245..55bcde4c43fb06 100644 --- a/Lib/test/test_string_literals.py +++ b/Lib/test/test_string_literals.py @@ -109,18 +109,18 @@ def test_eval_str_invalid_escape(self): for b in range(1, 128): if b in b"""\n\r"'01234567NU\\abfnrtuvx""": continue - with self.assertWarns(DeprecationWarning): + with self.assertWarns(SyntaxWarning): self.assertEqual(eval(r"'\%c'" % b), '\\' + chr(b)) with warnings.catch_warnings(record=True) as w: - warnings.simplefilter('always', category=DeprecationWarning) + warnings.simplefilter('always', category=SyntaxWarning) eval("'''\n\\z'''") self.assertEqual(len(w), 1) self.assertEqual(w[0].filename, '') self.assertEqual(w[0].lineno, 2) with warnings.catch_warnings(record=True) as w: - warnings.simplefilter('error', category=DeprecationWarning) + warnings.simplefilter('error', category=SyntaxWarning) with self.assertRaises(SyntaxError) as cm: eval("'''\n\\z'''") exc = cm.exception @@ -158,18 +158,18 @@ def test_eval_bytes_invalid_escape(self): for b in range(1, 128): if b in b"""\n\r"'01234567\\abfnrtvx""": continue - with self.assertWarns(DeprecationWarning): + with self.assertWarns(SyntaxWarning): self.assertEqual(eval(r"b'\%c'" % b), b'\\' + bytes([b])) with warnings.catch_warnings(record=True) as w: - warnings.simplefilter('always', category=DeprecationWarning) + warnings.simplefilter('always', category=SyntaxWarning) eval("b'''\n\\z'''") self.assertEqual(len(w), 1) self.assertEqual(w[0].filename, '') self.assertEqual(w[0].lineno, 2) with warnings.catch_warnings(record=True) as w: - warnings.simplefilter('error', category=DeprecationWarning) + warnings.simplefilter('error', category=SyntaxWarning) with self.assertRaises(SyntaxError) as cm: eval("b'''\n\\z'''") exc = cm.exception diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index c358756bfea8e6..6c609fcab7e04e 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -1255,7 +1255,7 @@ PyObject *PyBytes_DecodeEscape(const char *s, if (result == NULL) return NULL; if (first_invalid_escape != NULL) { - if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, + if (PyErr_WarnFormat(PyExc_SyntaxWarning, 1, "invalid escape sequence '\\%c'", (unsigned char)*first_invalid_escape) < 0) { Py_DECREF(result); diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 1ae2f5e018fe8e..69f967c92b072c 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -6109,7 +6109,7 @@ PyUnicode_DecodeUnicodeEscape(const char *s, if (result == NULL) return NULL; if (first_invalid_escape != NULL) { - if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, + if (PyErr_WarnFormat(PyExc_SyntaxWarning, 1, "invalid escape sequence '\\%c'", (unsigned char)*first_invalid_escape) < 0) { Py_DECREF(result); diff --git a/Python/ast.c b/Python/ast.c index e2092f0f85433e..9502c7065f30da 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -4158,11 +4158,11 @@ warn_invalid_escape_sequence(struct compiling *c, const node *n, if (msg == NULL) { return -1; } - if (PyErr_WarnExplicitObject(PyExc_DeprecationWarning, msg, + if (PyErr_WarnExplicitObject(PyExc_SyntaxWarning, msg, c->c_filename, LINENO(n), NULL, NULL) < 0) { - if (PyErr_ExceptionMatches(PyExc_DeprecationWarning)) { + if (PyErr_ExceptionMatches(PyExc_SyntaxWarning)) { const char *s; /* Replace the DeprecationWarning exception with a SyntaxError