[IPython-dev] getdoc hook

Frédéric Mantegazza mantegazza at ill.fr
Fri Apr 8 09:01:09 EDT 2005


Le Vendredi 8 Avril 2005 11:24, Fernando Perez a écrit :

> > Fernando, could it be possible to add a hook to rebind this function in
> > a better way ?
>
> Well, this is not really an ipython internal method which is hookable,
> it's just a plain function in a library (the OInspect module).  So what
> you are doing is about as simple a rebind as I can imagine (though I
> don't understand why it's failing in your case, sorry).

I will look further why it does not work...

> > It would also be nice to have a hook to change the whole
> > getdoc behaviour. I mean, I would like to use my own Inspector class
> > (at least to be able to overide some parts of it).
>
> Well, you can use your own inspector simply by setting:
>
> __IPYTHON__.inspector = your_inspector_instance

This is fine :o)

> > 2) Why is the getdoc() function always called, even when I don't use
> > the 'obj?' syntax ?
>
> Because in the input evaluation loop, while I find what you typed (to
> make auto-execution decisions and the like), once the object is found I
> fish out in passing the docstring.  A lot of the machinery that does many
> of the nice things in ipython needs to know quite a bit about the objects
> referenced by names at the command line, so I tried to centralize this
> collection of information in one place.  The actual routine is _ofind()
> in Magic.py (that probably belongs somewhere else like iplib.py, really).

So I will always have a call to the remote object getdoc() method (little 
overhead)...

> > 3) Is it possible make difference in 'obj.?' and 'obj.??' syntaxes at
> > the getdoc() level ? If not, where is it handled ?
>
> No. getdoc() gets passed a true object, not the input line which the
> user typed.  By the time getdoc is called, we've long forgotten the user
> input.  If you need to mess with that kind of thing, you need to put
> traps very early on in the line processing, that's what custom prefilters
> are for.

It was more for my general understanding rather than for a real need.

> Note that obj.?  doesn't work: 

Sorry, it was an error. I didn't want to say 'obj.?', but 'obj?'.

Thank's,

-- 
   Frédéric




More information about the IPython-dev mailing list