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: 2to3 creates illegal code on import a.b inside a package
Type: Stage: resolved
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder: Close 2to3 issues and list them here
View: 45544
Assigned To: Nosy List: benjamin.peterson, eric.araujo, meador.inge, simohe
Priority: normal Keywords:

Created on 2011-08-30 21:59 by simohe, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg143237 - (view) Author: simohe (simohe) Date: 2011-08-30 21:59
When the current module is in a package and imports submodules, the following lines are converted to illegal code.

-import sub.subsub
+from . import sub.subsub

-import sub, sub.subsub, sub2
+from . import sub, sub.subsub, sub2

A valid alternative:

-import sub.subsub
+from .sub import subsub as _dummy

-import sub, sub.subsub, sub2
+from . import sub, sub2\nfrom .sub import subsub as _dummy
msg156737 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012-03-25 07:03
-import sub.subsub
+from .sub import subsub as _dummy

That’s partly incorrect, as you need to bind the name sub to match the original code.
msg156738 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012-03-25 07:04
BTW I think if this is too difficult to implement 2to3 could just be documented as requiring you not to use implicit relative imports.
History
Date User Action Args
2022-04-11 14:57:21adminsetgithub: 57073
2021-10-20 22:40:51iritkatrielsetresolution: duplicate -> wont fix
2021-10-20 22:37:18iritkatrielsetstatus: open -> closed
superseder: Close 2to3 issues and list them here
resolution: duplicate
stage: needs patch -> resolved
2012-03-30 02:00:41meador.ingesetnosy: + meador.inge
2012-03-25 07:04:17eric.araujosetmessages: + msg156738
2012-03-25 07:03:35eric.araujosetnosy: + eric.araujo
messages: + msg156737
2011-09-02 16:59:43eric.araujosetnosy: + benjamin.peterson
stage: needs patch

versions: + Python 2.7, Python 3.2, Python 3.3, - Python 2.6, Python 3.1
2011-08-30 21:59:21simohecreate