summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorNitish Chandra <nitishchandrachinta@gmail.com>2018-01-28 10:56:02 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2018-01-28 10:56:02 (GMT)
commit43c0f1ac5ed8bc9c3bd048d2ce4de4c98a83de99 (patch)
treee2a5ab622dbb25f3ec3b6f66099ad1aaaab37acd /Lib
parent255f7a26da47ca6b7bd1d375b8a04920f68c119c (diff)
downloadcpython-43c0f1ac5ed8bc9c3bd048d2ce4de4c98a83de99.zip
cpython-43c0f1ac5ed8bc9c3bd048d2ce4de4c98a83de99.tar.gz
cpython-43c0f1ac5ed8bc9c3bd048d2ce4de4c98a83de99.tar.bz2
bpo-32685: Improve suggestion for print statement (GH-5375)
Better account for single-line compound statements and semi-colon separated statements when suggesting Py3 replacements for Py2 print statements. Initial patch by Nitish Chandra.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_print.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_print.py b/Lib/test/test_print.py
index 7bc23cf..e838112 100644
--- a/Lib/test/test_print.py
+++ b/Lib/test/test_print.py
@@ -165,6 +165,23 @@ class TestPy2MigrationHint(unittest.TestCase):
self.assertIn('print("Hello World")', 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
+ # and/or followed by a semicolon
+ def test_string_with_semicolon(self):
+ python2_print_str = 'print p;'
+ with self.assertRaises(SyntaxError) as context:
+ exec(python2_print_str)
+
+ self.assertIn('print(p)', 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))
+
def test_stream_redirection_hint_for_py2_migration(self):
# Test correct hint produced for Py2 redirection syntax
with self.assertRaises(TypeError) as context: