Issue 12864: 2to3 creates illegal code on import a.b inside a package - Python tracker

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
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.