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

benjamin.peterson python-checkins at python.org
Fri Apr 9 23:11:44 CEST 2010


Author: benjamin.peterson
Date: Fri Apr  9 23:11:44 2010
New Revision: 79917

Log:
don't try to 'fix' relative imports when absolute_import is enabled #8858

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

Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_import.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_import.py	(original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_import.py	Fri Apr  9 23:11:44 2010
@@ -43,7 +43,13 @@
     import_name< 'import' imp=any >
     """
 
+    def start_tree(self, tree, name):
+        super(FixImport, self).start_tree(tree, name)
+        self.skip = "absolute_import" in tree.future_features
+
     def transform(self, node, results):
+        if self.skip:
+            return
         imp = results['imp']
 
         if node.type == syms.import_from:

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	Fri Apr  9 23:11:44 2010
@@ -3722,6 +3722,12 @@
         self.present_files = set(["bar.py"])
         self.unchanged(s)
 
+    def test_with_absolute_import_enabled(self):
+        s = "from __future__ import absolute_import\nimport bar"
+        self.always_exists = False
+        self.present_files = set(["__init__.py", "bar.py"])
+        self.unchanged(s)
+
     def test_in_package(self):
         b = "import bar"
         a = "from . import bar"


More information about the Python-checkins mailing list