[SciPy-dev] Postponed imports and docstrings

Arnd Baecker arnd.baecker at web.de
Wed Nov 3 04:02:15 CST 2004


On Wed, 3 Nov 2004, Pearu Peterson wrote:

> On Tue, 2 Nov 2004, Fernando Perez wrote:
>
> >> Fernando, could you point out which part of ipython implements `?..`
> >> so that I could look into it and fix the in scipy_base/ppimport.py?
> >
> > Sure, it's mostly done by the code in Magic.py, method _ofind around line
> > 228.   When you type 'foo?', ipython really issues '%pinfo foo', which makes
> > a call to _ofind('foo') to pull out the object pointed to by the name 'foo',
> > along with some info about it.  This is then passed to OInspect's pinfo()
> > method, which builds the full information page.
> >
> > Note that I tried a bunch of tricks for a couple of hours, trying to repeat
> > the object detection inside _ofind() when scipy objects were involved, but I
> > failed to fix the problem.  So unfortunately, I'll have to defer to you for a
> > proper solution.  I was expecting that perhaps I could toss in a small hack
> > to solve this on the ipython side, but I can't seem to be able to replicate
> > with a simple change the behavior of a repeated 'foo?' call.  This is
> > probably because I don't really understand the delayed import mechanism, and
> > in reality a proper fix in scipy is probably the right approach.
>
> Thanks for the tips. The fix to the problem was simpler: inspect.getdoc
> required a wrapper that applies ppresolve to its argument. Now ?optimize
> works also in first attempt.

Great - many thanks!!!

Does this also solve the problem when pressing <TAB> in IPython?

In [1]: import scipy

In [2]: scipy.optimize.     # <TAB> pressed here
scipy.optimize.__class__           scipy.optimize.__repr__
scipy.optimize.__doc__             scipy.optimize.__setattr__
scipy.optimize.__file__            scipy.optimize.__str__
scipy.optimize.__getattr__         scipy.optimize._ppimport_importer
scipy.optimize.__init__            scipy.optimize._ppimport_p_frame
scipy.optimize.__module__          scipy.optimize.test
scipy.optimize.__name__

In [2]: scipy.optimize.    # pressing <TAB> the second time

So pressing <TAB> the second time gives the full list of options.

It would be nice if this worked as well.

Again, many thanks,

Arnd




More information about the Scipy-dev mailing list