[IPython-dev] strange namespace issue

Darren Dale dd55 at cornell.edu
Tue Sep 11 17:09:46 EDT 2007


On Tuesday 11 September 2007 01:56:14 pm Darren Dale wrote:
> On Tuesday 11 September 2007 01:18:04 pm Fernando Perez wrote:
> > On 9/11/07, Darren Dale <dd55 at cornell.edu> wrote:
> > > Aha! The problem was introduced in svn 2754, when iplib, FakeModule and
> > > Magic were modified. Try doing the following with svn 2753 and then
> > > 2754:
> > >
> > > $ ipython -gthread
> > > In [1]: run pygtk-demo.py
> > > # interact with the pygtk-demo window
> > >
> > > I get errors with 2754, but not with 2753.
> >
> > Lovely.  Those are the changes I made for doctest to work correctly,
> > and the more frustrating part is that the new code is in a sense much
> > more correct.  Instead of building a fake contraption that tries to
> > look like a module, we actually put a true module object in the
> > execution namespace of the called script.  This could not be done back
> > in the days of python 2.1, but now (post 2.2) I can do that, which
> > should be a much better solution.
[...]
> -            prog_ns = {'__name__':name}
> +            main_mod = FakeModule()
> +            prog_ns = main_mod.__dict__
> +            prog_ns['__name__'] = name
>
>          # Since '%run foo' emulates 'python foo.py' at the cmd line, we
> must # set the __file__ global in the script's namespace
> @@ -1540,7 +1543,7 @@
>          else:
>              restore_main = False
>
> -        sys.modules[prog_ns['__name__']] = FakeModule(prog_ns)
> +        sys.modules[prog_ns['__name__']] = main_mod

These are the specific changes that are causing some trouble. I dont quite 
follow what is being done here. Is a module being injected into the 
namespace, or is the entire namespace being overwritten? This post I pointed 
out earlier (http://osdir.com/ml/web.zope.devel/2004-02/msg00051.html) might 
still be relevant. Maybe the new code is overwriting an important namespace 
reference, and should instead be updating it?



More information about the IPython-dev mailing list