This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: lib2to3.fixes.fix_import gets confused if implicit relative imports and absolute imports are on the same line
Type: Stage: resolved
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.3
process
Status: closed Resolution: wont fix
Dependencies: Superseder: Close 2to3 issues and list them here
View: 45544
Assigned To: Nosy List: BTaskaya, benjamin.peterson, durin42, eric.araujo, twouters
Priority: normal Keywords:

Created on 2013-11-06 00:27 by durin42, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg202248 - (view) Author: Augie Fackler (durin42) * Date: 2013-11-06 00:27
While tinkering (again) with Mercurial Python 3 messes, I ran across this gem:

import error, osutil, encoding, collections

(http://selenic.com/hg/file/e1317d3e59e1/mercurial/util.py#l17)

That import statement contains 3 relative imports (that is, mercurial.error, mercurial.osutil, and mercurial.encoding), and one standard library import (collections). Because of the standard lib import on that line, lib2to3 doesn't rewrite any of the imports. If I instead move collections to its own line, then the first three imports get correctly rewritten to the "from . import error" form.

I've got Python 3.3.2 locally, and the lib2to3 is the one from that stdlib.
msg213587 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2014-03-14 19:32
To be fair to 2to3, that line disrespects some Python best practices (use explicit relative imports (2.5+), put one import per line, group imports by stdlib/non-stdlib).  It’s still a bug though :)
msg355637 - (view) Author: Batuhan Taskaya (BTaskaya) * (Python committer) Date: 2019-10-29 09:46
> It’s still a bug though :)

It gives a warning about this though
     RefactoringTool: ### In file test/t.py ###
     RefactoringTool: Line 1: absolute and local imports together

If it still counts as a bug, let me know and i'll try to prepare a patch.
History
Date User Action Args
2022-04-11 14:57:53adminsetgithub: 63709
2021-10-20 22:57:09iritkatrielsetstatus: open -> closed
superseder: Close 2to3 issues and list them here
resolution: wont fix
stage: resolved
2019-10-29 09:46:15BTaskayasetnosy: + BTaskaya
messages: + msg355637
2014-03-14 19:32:26eric.araujosetnosy: + eric.araujo, benjamin.peterson
messages: + msg213587
2013-11-06 00:27:39durin42create