mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
bpo-32912: Replace a DeprecationWarning with a SyntaxWarning (GH-9652)
for invalid escape sequences in string and bytes literals.
This commit is contained in:
parent
209144831b
commit
6543912c90
6 changed files with 23 additions and 12 deletions
|
@ -109,18 +109,18 @@ class TestLiterals(unittest.TestCase):
|
|||
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, '<string>')
|
||||
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 @@ class TestLiterals(unittest.TestCase):
|
|||
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, '<string>')
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue