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 does relative import for modules not in a package.
Type: Stage:
Components: 2to3 (2.x to 3.x conversion tool) Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, mhammond
Priority: normal Keywords: patch

Created on 2008-09-30 13:20 by mhammond, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
relative_must_be_package.patch mhammond, 2008-09-30 13:20 check module is in a package before assuming a relative import.
Messages (4)
msg74075 - (view) Author: Mark Hammond (mhammond) * (Python committer) Date: 2008-09-30 13:20
Create an empty directory with only 2 files, foo.py and bar.py, both
exactly 1 line:

foo.py:
|from bar import bar
bar.py:
|bar = "bar"

Running 2to3 results in the following patch for foo.py:
-from bar import bar
+from .bar import bar

However, the resulting foo.py fails to run - the 2 files are not in a
package, so we get:

| ValueError: Attempted relative import in non-package

Attaching a patch which checks there is an __init__.py in the same
directory as the files before it considers it a potential relative import.
msg74103 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-09-30 23:27
Thanks. Fixed in r66707.
msg74289 - (view) Author: Mark Hammond (mhammond) * (Python committer) Date: 2008-10-04 00:39
I must be going crazy, but I can't see r66707 in the trunk, the py3k
branch, or anywhere else in the svn tree.  Can you please lend me a
clue-stick?
msg74290 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-10-04 00:40
On Fri, Oct 3, 2008 at 7:39 PM, Mark Hammond <report@bugs.python.org> wrote:
>
> Mark Hammond <mhammond@users.sourceforge.net> added the comment:
>
> I must be going crazy, but I can't see r66707 in the trunk, the py3k
> branch, or anywhere else in the svn tree.  Can you please lend me a
> clue-stick?

You're not crazy; it's just hidden. :)

It's in the 2to3 main line of development: /sandbox/trunk/2to3

I'll merge into the trunk and py3k soon.
History
Date User Action Args
2022-04-11 14:56:39adminsetgithub: 48251
2008-10-04 00:40:17benjamin.petersonsetmessages: + msg74290
2008-10-04 00:39:06mhammondsetmessages: + msg74289
2008-09-30 23:27:23benjamin.petersonsetstatus: open -> closed
resolution: fixed
messages: + msg74103
nosy: + benjamin.peterson
2008-09-30 13:20:31mhammondcreate