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

christian.heimes python-checkins at python.org
Sun Dec 2 12:56:36 CET 2007


Author: christian.heimes
Date: Sun Dec  2 12:56:35 2007
New Revision: 59269

Modified:
   sandbox/trunk/2to3/fixes/fix_imports.py
   sandbox/trunk/2to3/tests/test_fixers.py
Log:
Added a fixer for r59268
#1535: rename __builtin__ module to builtins.

Modified: sandbox/trunk/2to3/fixes/fix_imports.py
==============================================================================
--- sandbox/trunk/2to3/fixes/fix_imports.py	(original)
+++ sandbox/trunk/2to3/fixes/fix_imports.py	Sun Dec  2 12:56:35 2007
@@ -10,9 +10,14 @@
 # Local imports
 from fixes import basefix
 from fixes.util import Name, attr_chain, any, set
+import __builtin__
+builtin_names = [name for name in dir(__builtin__)
+                 if name not in ("__name__", "__doc__")]
 
 MAPPING = {"StringIO":  ("io", ["StringIO"]),
-           "cStringIO": ("io", ["StringIO"])}
+           "cStringIO": ("io", ["StringIO"]),
+           "__builtin__" : ("builtins", builtin_names), 
+          }
 
 
 def alternates(members):

Modified: sandbox/trunk/2to3/tests/test_fixers.py
==============================================================================
--- sandbox/trunk/2to3/tests/test_fixers.py	(original)
+++ sandbox/trunk/2to3/tests/test_fixers.py	Sun Dec  2 12:56:35 2007
@@ -1270,7 +1270,10 @@
     fixer = "imports"
 
     modules = {"StringIO":  ("io", ["StringIO"]),
-               "cStringIO": ("io", ["StringIO"])}
+               "cStringIO": ("io", ["StringIO"]),
+               "__builtin__" : ("builtins", ["open", "Exception",
+                   "__debug__", "str"]),
+              }
 
     def test_import_module(self):
         for old, (new, members) in self.modules.items():
@@ -1285,11 +1288,11 @@
     def test_import_from(self):
         for old, (new, members) in self.modules.items():
             for member in members:
-                b = "from %s import %s" % (old, ", ".join(members))
-                a = "from %s import %s" % (new, ", ".join(members))
+                b = "from %s import %s" % (old, member)
+                a = "from %s import %s" % (new, member)
                 self.check(b, a)
 
-                s = "from foo import %s" % ", ".join(members)
+                s = "from foo import %s" % member
                 self.unchanged(s)
 
     def test_import_module_as(self):
@@ -1305,8 +1308,8 @@
     def test_import_from_as(self):
         for old, (new, members) in self.modules.items():
             for member in members:
-                b = "from %s import %s as foo_bar" % (old, ", ".join(members))
-                a = "from %s import %s as foo_bar" % (new, ", ".join(members))
+                b = "from %s import %s as foo_bar" % (old, member)
+                a = "from %s import %s as foo_bar" % (new, member)
                 self.check(b, a)
 
     def test_star(self):


More information about the Python-checkins mailing list