diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-07-27 21:19:18 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-27 21:19:18 (GMT) |
commit | 68e3dca0687c4c8e61ed98aed82f81049880c0ce (patch) | |
tree | 09303b22a3cfb3c9e788ceb4219840200ff42b00 /Lib | |
parent | b977f8510e2ff4f11e3bda920722098a242fc8cc (diff) | |
download | cpython-68e3dca0687c4c8e61ed98aed82f81049880c0ce.zip cpython-68e3dca0687c4c8e61ed98aed82f81049880c0ce.tar.gz cpython-68e3dca0687c4c8e61ed98aed82f81049880c0ce.tar.bz2 |
bpo-34013: Move the Python 2 hints from the exception constructor to the parser (GH-27392)
(cherry picked from commit ecc3c8e4216958d85385bf2467441c975128f26c)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_exceptions.py | 12 | ||||
-rw-r--r-- | Lib/test/test_print.py | 18 |
2 files changed, 17 insertions, 13 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 8caac2c..8ffebeb 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -168,21 +168,19 @@ class ExceptionTests(unittest.TestCase): self.fail("failed to get expected SyntaxError") s = '''print "old style"''' - ckmsg(s, "Missing parentheses in call to 'print'. " - "Did you mean print(\"old style\")?") + ckmsg(s, "Missing parentheses in call to 'print'. Did you mean print(...)?") s = '''print "old style",''' - ckmsg(s, "Missing parentheses in call to 'print'. " - "Did you mean print(\"old style\", end=\" \")?") + ckmsg(s, "Missing parentheses in call to 'print'. Did you mean print(...)?") s = 'print f(a+b,c)' - ckmsg(s, "Missing parentheses in call to 'print'.") + ckmsg(s, "Missing parentheses in call to 'print'. Did you mean print(...)?") s = '''exec "old style"''' - ckmsg(s, "Missing parentheses in call to 'exec'") + ckmsg(s, "Missing parentheses in call to 'exec'. Did you mean exec(...)?") s = 'exec f(a+b,c)' - ckmsg(s, "Missing parentheses in call to 'exec'.") + ckmsg(s, "Missing parentheses in call to 'exec'. Did you mean exec(...)?") # should not apply to subclasses, see issue #31161 s = '''if True:\nprint "No indent"''' diff --git a/Lib/test/test_print.py b/Lib/test/test_print.py index e838112..5f1bfd9 100644 --- a/Lib/test/test_print.py +++ b/Lib/test/test_print.py @@ -140,21 +140,24 @@ class TestPy2MigrationHint(unittest.TestCase): with self.assertRaises(SyntaxError) as context: exec(python2_print_str) - self.assertIn('print("Hello World")', str(context.exception)) + self.assertIn("Missing parentheses in call to 'print'. Did you mean print(...)", + str(context.exception)) def test_string_with_soft_space(self): python2_print_str = 'print "Hello World",' with self.assertRaises(SyntaxError) as context: exec(python2_print_str) - self.assertIn('print("Hello World", end=" ")', str(context.exception)) + self.assertIn("Missing parentheses in call to 'print'. Did you mean print(...)", + str(context.exception)) def test_string_with_excessive_whitespace(self): python2_print_str = 'print "Hello World", ' with self.assertRaises(SyntaxError) as context: exec(python2_print_str) - self.assertIn('print("Hello World", end=" ")', str(context.exception)) + self.assertIn("Missing parentheses in call to 'print'. Did you mean print(...)", + str(context.exception)) def test_string_with_leading_whitespace(self): python2_print_str = '''if 1: @@ -163,7 +166,8 @@ class TestPy2MigrationHint(unittest.TestCase): with self.assertRaises(SyntaxError) as context: exec(python2_print_str) - self.assertIn('print("Hello World")', str(context.exception)) + self.assertIn("Missing parentheses in call to 'print'. Did you mean print(...)", + str(context.exception)) # bpo-32685: Suggestions for print statement should be proper when # it is in the same line as the header of a compound statement @@ -173,14 +177,16 @@ class TestPy2MigrationHint(unittest.TestCase): with self.assertRaises(SyntaxError) as context: exec(python2_print_str) - self.assertIn('print(p)', str(context.exception)) + self.assertIn("Missing parentheses in call to 'print'. Did you mean print(...)", + str(context.exception)) def test_string_in_loop_on_same_line(self): python2_print_str = 'for i in s: print i' with self.assertRaises(SyntaxError) as context: exec(python2_print_str) - self.assertIn('print(i)', str(context.exception)) + self.assertIn("Missing parentheses in call to 'print'. Did you mean print(...)", + str(context.exception)) def test_stream_redirection_hint_for_py2_migration(self): # Test correct hint produced for Py2 redirection syntax |