[Python-Dev] Bug in 2to3 concerning import statements? (original) (raw)
Brett Cannon brett at python.org
Sun May 1 12:23:55 EDT 2016
- Previous message (by thread): [Python-Dev] Memory
- Next message (by thread): [Python-Dev] Bug in 2to3 concerning import statements?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sat, 30 Apr 2016 at 21:51 Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
It seems that 2to3 is a bit simplistic when it comes to translating import statements. I have a module GUI.py2exe containing:
import py2exe.mf as modulefinder 2to3 translates this into: from . import py2exe.mf as modulefinder which is a syntax error. It looks like 2to3 is getting confused by the fact that there is both a submodule and a top-level module here called py2exe.
That sounds right. 2to3 has to inspect the environment to figure out if the import was meant to be relative or absolute and it's getting confused.
But the original can only be an absolute import because it has a dot in it, so 2to3 shouldn't be translating it into a relative one.
2to3 is nowhere near that sophisticated for tweaking imports :)
Putting "from future import absoluteimport" at the top fixes it, but I shouldn't have to do that, should I?
There's all sorts of weird stuff going on in that import, like having a dot
in the from
part of the import instead of doing from .py2exe import mf as modulefinder
. Try that tweak and see if that solves your SyntaxError
for some reason.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20160501/3111d4f6/attachment.html>
- Previous message (by thread): [Python-Dev] Memory
- Next message (by thread): [Python-Dev] Bug in 2to3 concerning import statements?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]