[Python-checkins] r58065 - in sandbox/trunk/2to3: fixes/fix_print.py tests/test_fixers.py

collin.winter python-checkins at python.org
Mon Sep 10 01:30:52 CEST 2007


Author: collin.winter
Date: Mon Sep 10 01:30:51 2007
New Revision: 58065

Modified:
   sandbox/trunk/2to3/fixes/fix_print.py
   sandbox/trunk/2to3/tests/test_fixers.py
Log:
Fix a bug in fix_print where 'print T' where T is a tuple would be mis-translated.

Modified: sandbox/trunk/2to3/fixes/fix_print.py
==============================================================================
--- sandbox/trunk/2to3/fixes/fix_print.py	(original)
+++ sandbox/trunk/2to3/fixes/fix_print.py	Mon Sep 10 01:30:51 2007
@@ -18,7 +18,9 @@
 from fixes.util import Name, Call, Comma, String, is_tuple
 
 
-paren_call = patcomp.compile_pattern("""atom< '(' any ')' >""")
+parend_expr = patcomp.compile_pattern(
+              """atom< '(' [atom|STRING|NAME] ')' >"""
+              )
 
 
 class FixPrint(basefix.BaseFix):
@@ -38,11 +40,12 @@
             return
         assert node.children[0] == Name("print")
         args = node.children[1:]
-        sep = end = file = None
-        if len(args) == 1 and (is_tuple(args[0]) or paren_call.match(args[0])):
+        if len(args) == 1 and parend_expr.match(args[0]):
             # We don't want to keep sticking parens around an
             # already-parenthesised expression.
             return
+
+        sep = end = file = None
         if args and args[-1] == Comma():
             args = args[:-1]
             end = " "

Modified: sandbox/trunk/2to3/tests/test_fixers.py
==============================================================================
--- sandbox/trunk/2to3/tests/test_fixers.py	(original)
+++ sandbox/trunk/2to3/tests/test_fixers.py	Mon Sep 10 01:30:51 2007
@@ -348,9 +348,6 @@
         self.check(b, a)
 
     def test_idempotency(self):
-        s = """print(1, 1+1, 1+1+1)"""
-        self.unchanged(s)
-
         s = """print()"""
         self.unchanged(s)
 
@@ -386,6 +383,11 @@
         a = """print()"""
         self.check(b, a)
 
+    def test_tuple(self):
+        b = """print (a, b, c)"""
+        a = """print((a, b, c))"""
+        self.check(b, a)
+
     # trailing commas
 
     def test_trailing_comma_1(self):


More information about the Python-checkins mailing list