[Python-ideas] Module local namespaces

Brett Cannon brett at python.org
Thu Jan 4 03:29:05 CET 2007


On 1/3/07, Josiah Carlson <jcarlson at uci.edu> wrote:
>
>
> "Guido van Rossum" <guido at python.org> wrote:
> > On 1/3/07, Josiah Carlson <jcarlson at uci.edu> wrote:
> > > -1 .  The only thing that possibly should be fixed is that modules
> > > should only be inserted into sys.modules after they have been imported
> > > completely and correctly.
> >
> > I agree, but there's the wrinkle that during recursive imports you
> > want partially-imported modules to be importable. I believe we once
> > agreed on a solution but I don't recall what it was. Does anybody
> > remember?
>
> I don't remember what was agreed upon, but what about something like...
>
>     try:
>         newmodule = ...
>         sys.modules[name] = newmodule
>         handle_the_import(newmodule, ...)
>     except:
>         del sys.modules[name]
>         raise



My re-implementation does exactly that (I just sometimes postpone the module
creation to the top of the handle_the_import function).

-Brett
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20070103/83dc1459/attachment.html>


More information about the Python-ideas mailing list