Title: intra-pkg multiple import (import local1, local2) not fixed
Type: Stage:
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.0
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, sjmachin
Priority: normal Keywords:

Created on 2008-12-25 00:42 by sjmachin, last changed 2008-12-27 02:50 by benjamin.peterson. This issue is now closed.

Messages (2)
msg78276 - (view) Author: John Machin (sjmachin) Date: 2008-12-25 00:42
In a package, "import local1, local2" is not fixed. Here's some real
live 2to3 output showing the problem and the workaround:
 import ExcelFormulaParser, ExcelFormulaLexer
-import ExcelFormulaParser
-import ExcelFormulaLexer
+from . import ExcelFormulaParser
+from . import ExcelFormulaLexer
 import sys, struct
-from antlr import ANTLRException
+from .antlr import ANTLRException

As a solution that covers cases like "import sys, local1, local2" is
possibly difficult, I suggest putting out a warning that a manual fix
(one import per line) may be required. I've put this kludge in my copy

 def probably_a_local_import(imp_name, file_path):
+    if "," in imp_name:
+        print("*** Can't handle import %r in %s" % (imp_name, file_path))
     # Must be stripped because the right space is included by the parser
     imp_name = imp_name.split('.', 1)[0].strip()
     base_path = dirname(file_path)
     base_path = join(base_path, imp_name)

[Aside: "right space"? Possibly should be "left space"]

and it produces:

*** Can't handle import ' ExcelFormulaParser, ExcelFormulaLexer' in
*** Can't handle import ' sys, struct' in
msg78333 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-12-27 02:50
r67928 makes 2to3 more tolerant about multiple imports on a line. It
also warns when there is an absolute import and relative import on the
same line.
Date User Action Args
2008-12-27 02:50:14benjamin.petersonsetstatus: open -> closed
resolution: fixed
messages: + msg78333
nosy: + benjamin.peterson
2008-12-25 00:42:05sjmachincreate