[New-bugs-announce] [issue4001] 2to3 does relative import for modules not in a package.

Mark Hammond report at bugs.python.org
Tue Sep 30 15:20:32 CEST 2008


New submission from Mark Hammond <mhammond at users.sourceforge.net>:

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.

----------
components: 2to3 (2.x to 3.0 conversion tool)
files: relative_must_be_package.patch
keywords: patch
messages: 74075
nosy: mhammond
severity: normal
status: open
title: 2to3 does relative import for modules not in a package.
Added file: http://bugs.python.org/file11662/relative_must_be_package.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4001>
_______________________________________


More information about the New-bugs-announce mailing list