[Python-ideas] Allow 'import star' with namespaces

Nick Coghlan ncoghlan at gmail.com
Mon May 9 19:16:52 CEST 2011


On Tue, May 10, 2011 at 3:02 AM, Guido van Rossum <guido at python.org> wrote:
> On Mon, May 9, 2011 at 7:04 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
>> This is one of the reasons circular imports are such a pain - we
>> pre-bind them in sys.modules, and remove them again if the import
>> fails, but we don't currently do that in the parent package namespace,
>> so circular imports sometimes work and sometime break depending not
>> only on which names are accessed but also *how* they're accessed (e.g.
>> in a/b/c.py, "import a.b.c" will work, "import a.b.c; c = a.b.c" will
>> fail with AttributeError and "from a.b import c" will fail with
>> ImportError).
>
> Maybe that's something we could strive to fix?

The relevant bug is still open: http://bugs.python.org/issue992389

My recollection is that the division of responsibility between the
core import code and PEP 302 loaders gets a little confused on this
point (although I don't recall if that's a real confusion or just an
artefact of the structure of the legacy import code).

It will hopefully be a little easier to fix once importlib takes over
from import.c and the pre-PEP 302 legacy stuff goes away.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-ideas mailing list