[Python-checkins] r80573 - in sandbox/trunk/2to3/lib2to3: fixes/fix_import.py tests/test_fixers.py
jeffrey.yasskin
python-checkins at python.org
Wed Apr 28 06:08:27 CEST 2010
Author: jeffrey.yasskin
Date: Wed Apr 28 06:08:27 2010
New Revision: 80573
Log:
Don't transform imports that are already relative. 2to3 turned
from . import refactor
into
from .. import refactor
which broke the transformation of 2to3 itself.
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 Wed Apr 28 06:08:27 2010
@@ -82,6 +82,9 @@
return new
def probably_a_local_import(self, imp_name):
+ if imp_name.startswith(u"."):
+ # Relative imports are certainly not local imports.
+ return False
imp_name = imp_name.split(u".", 1)[0]
base_path = dirname(self.filename)
base_path = join(base_path, imp_name)
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 Wed Apr 28 06:08:27 2010
@@ -3742,6 +3742,10 @@
self.present_files = set(["__init__.py", "bar" + os.path.sep])
self.check(b, a)
+ def test_already_relative_import(self):
+ s = "from . import bar"
+ self.unchanged(s)
+
def test_comments_and_indent(self):
b = "import bar # Foo"
a = "from . import bar # Foo"
More information about the Python-checkins
mailing list