(original) (raw)
On 4/21/06, guido.van.rossum <python-3000-checkins@python.org> wrote:
Hm, this is possibly a flaw in the explicit relative import mechanism. Normal circular imports work because a module object is stuffed into sys.modules before any code for the module is executed, so the next 'import' of that module just finds the half-loaded module object. I guess 'from . import name' really looks at the package contents, though, and there, the module isn't stored until it's done loading. I'm not sure why it raises a 'cannot import name' exception instead of recursing into a spiral of death, but I guess that's a good thing. :)
Should this be fixed, or is it an esoteric enough case that I shouldn't bother?
--
The hardest part was fixing two mutual recursive imports;
somehow changing "import foo" into "from . import foo" where
foo and bar import each other AND both are imported from __init__.py caused things to break. Bah.
Hm, this is possibly a flaw in the explicit relative import mechanism. Normal circular imports work because a module object is stuffed into sys.modules before any code for the module is executed, so the next 'import' of that module just finds the half-loaded module object. I guess 'from . import name' really looks at the package contents, though, and there, the module isn't stored until it's done loading. I'm not sure why it raises a 'cannot import name' exception instead of recursing into a spiral of death, but I guess that's a good thing. :)
Should this be fixed, or is it an esoteric enough case that I shouldn't bother?
Thomas Wouters <thomas@python.org>
Hi! I'm a .signature virus! copy me into your .signature file to help me spread!