mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
bpo-32912: Revert SyntaxWarning on invalid escape sequences. (GH-15195)
DeprecationWarning will continue to be emitted for invalid escape
sequences in string and bytes literals just as it did in 3.7.
SyntaxWarning may be emitted in the future. But per mailing list
discussion, we don't yet know when because we haven't settled on how to
do so in a non-disruptive manner.
(Applies 4c5b6bac24
to the master branch).
(This is https://github.com/python/cpython/pull/15142 for master/3.9)
https://bugs.python.org/issue32912
Automerge-Triggered-By: @gpshead
This commit is contained in:
parent
92c7e30adf
commit
b4be87a04a
6 changed files with 43 additions and 18 deletions
|
@ -32,6 +32,7 @@ import sys
|
|||
import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
import warnings
|
||||
|
||||
|
||||
TEMPLATE = r"""# coding: %s
|
||||
|
@ -110,10 +111,24 @@ class TestLiterals(unittest.TestCase):
|
|||
for b in range(1, 128):
|
||||
if b in b"""\n\r"'01234567NU\\abfnrtuvx""":
|
||||
continue
|
||||
with self.assertWarns(SyntaxWarning):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
self.assertEqual(eval(r"'\%c'" % b), '\\' + chr(b))
|
||||
|
||||
self.check_syntax_warning("'''\n\\z'''")
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter('always', category=DeprecationWarning)
|
||||
eval("'''\n\\z'''")
|
||||
self.assertEqual(len(w), 1)
|
||||
self.assertEqual(w[0].filename, '<string>')
|
||||
self.assertEqual(w[0].lineno, 1)
|
||||
|
||||
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, 1)
|
||||
|
||||
def test_eval_str_raw(self):
|
||||
self.assertEqual(eval(""" r'x' """), 'x')
|
||||
|
@ -145,10 +160,24 @@ class TestLiterals(unittest.TestCase):
|
|||
for b in range(1, 128):
|
||||
if b in b"""\n\r"'01234567\\abfnrtvx""":
|
||||
continue
|
||||
with self.assertWarns(SyntaxWarning):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
self.assertEqual(eval(r"b'\%c'" % b), b'\\' + bytes([b]))
|
||||
|
||||
self.check_syntax_warning("b'''\n\\z'''")
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter('always', category=DeprecationWarning)
|
||||
eval("b'''\n\\z'''")
|
||||
self.assertEqual(len(w), 1)
|
||||
self.assertEqual(w[0].filename, '<string>')
|
||||
self.assertEqual(w[0].lineno, 1)
|
||||
|
||||
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, 1)
|
||||
|
||||
def test_eval_bytes_raw(self):
|
||||
self.assertEqual(eval(""" br'x' """), b'x')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue