[Python-ideas] Module local namespaces
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...
> newmodule = ...
> sys.modules[name] = newmodule
> handle_the_import(newmodule, ...)
> del sys.modules[name]
My re-implementation does exactly that (I just sometimes postpone the module
creation to the top of the handle_the_import function).
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas