[Python-checkins] r67170 - in sandbox/trunk/2to3/lib2to3: fixes/fix_imports.py tests/test_fixers.py

benjamin.peterson python-checkins at python.org
Sat Nov 8 19:28:31 CET 2008


Author: benjamin.peterson
Date: Sat Nov  8 19:28:31 2008
New Revision: 67170

Log:
fix #4271: fix_imports didn't recognize imports with parenthesis (ie from x import (a, b))

Modified:
   sandbox/trunk/2to3/lib2to3/fixes/fix_imports.py
   sandbox/trunk/2to3/lib2to3/tests/test_fixers.py

Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_imports.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_imports.py	(original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_imports.py	Sat Nov  8 19:28:31 2008
@@ -66,9 +66,9 @@
     yield """import_name< 'import' ((%s)
                           | dotted_as_names< any* (%s) any* >) >
           """ % (mod_list, mod_list)
-    yield """import_from< 'from' (%s) 'import'
+    yield """import_from< 'from' (%s) 'import' ['(']
               ( any | import_as_name< any 'as' any > |
-                import_as_names< any* >) >
+                import_as_names< any* >)  [')'] >
           """ % mod_name_list
     yield """import_name< 'import'
                           dotted_as_name< (%s) 'as' any > >

Modified: sandbox/trunk/2to3/lib2to3/tests/test_fixers.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/tests/test_fixers.py	(original)
+++ sandbox/trunk/2to3/lib2to3/tests/test_fixers.py	Sat Nov  8 19:28:31 2008
@@ -1470,6 +1470,12 @@
             a = "from %s import *" % new
             self.check(b, a)
 
+    def test_parenthesis(self):
+        for old, new in self.modules.items():
+            b = "from %s import (yes, no)" % old
+            a = "from %s import (yes, no)" % new
+            self.check(b, a)
+
     def test_import_module_usage(self):
         for old, new in self.modules.items():
             b = """


More information about the Python-checkins mailing list