Nested packages and import order bug
ianb at colorstudy.com
Mon Oct 6 19:58:44 CEST 2003
On Monday, October 6, 2003, at 11:53 AM, Joerg Sonnenberger wrote:
> Hi all,
> I have a package a.b with the following content:
> import a.b
> Running "import a.b" generates an AttributeError for b, obviously
> the import didn't add b to the module "a". Even though it can be
> argued that importing a package from within is bad style, this
> a clearly a bug since its at least surprising.
This sort of bug is more common with circular imports, but in this case
the circle is very small (the module importing itself). The module
isn't "imported" until all its statements have been executed. When you
consider the statement execution order it's usually clear why it can't
> Shouldn't the import create the namespace entry in a after it
> created the module entry in sys.modules?
> Therefore should I submit a bug report?
This is not an entirely uncommon error -- or maybe it's more that when
it does occur it usually confuses people.
I don't think the behavior is a bug. Maybe it could have a better
error message, but I'm not entirely sure how you'd even detect this
More information about the Python-list