New submission from Alejandro Santos <alej...@alejolp.com>:

The 2to3 tool shipped with Python 3.1 final doesn't handle correctly a
local package import (fixer fix_import). Test case:

$ find . -name '*.py'
./__init__.py
./a.py
./b/__init__.py
./b/m.py

$ 2to3 a.py
RefactoringTool: Skipping implicit fixer: buffer
RefactoringTool: Skipping implicit fixer: idioms
RefactoringTool: Skipping implicit fixer: set_literal
RefactoringTool: Skipping implicit fixer: ws_comma
RefactoringTool: No files need to be modified.

$ cat a.py

from b import m

m.q()


Trying to use the 2to3 tool from one level up won't work either:

$ 2to3 test2to3/a.py
RefactoringTool: Skipping implicit fixer: buffer
RefactoringTool: Skipping implicit fixer: idioms
RefactoringTool: Skipping implicit fixer: set_literal
RefactoringTool: Skipping implicit fixer: ws_comma
RefactoringTool: No files need to be modified.

It seems to be a bug in the fixer, which is using the os.path.pathsep
constant when it should be using the os.path.sep instead. 

The probably_a_local_import function is checking if "test2to3/b:"
exists, when it should be checking against: "test2to3/b/"

Attached patch seems to be working:

$ 2to3 test2to3/a.py
RefactoringTool: Skipping implicit fixer: buffer
RefactoringTool: Skipping implicit fixer: idioms
RefactoringTool: Skipping implicit fixer: set_literal
RefactoringTool: Skipping implicit fixer: ws_comma
--- test2to3/a.py (original)
+++ test2to3/a.py (refactored)
@@ -1,5 +1,5 @@
 
-from b import m
+from .b import m
 
 m.q()
 
RefactoringTool: Files that need to be modified:
RefactoringTool: test2to3/a.py

----------
components: 2to3 (2.x to 3.0 conversion tool)
files: 2to3-os.path.sep.path
messages: 90055
nosy: alejolp, djc
severity: normal
status: open
title: 2to3: Local package import
versions: Python 3.1
Added file: http://bugs.python.org/file14437/2to3-os.path.sep.path

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue6408>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to