[IPython-dev] making pdoc, pdef, and pinfo more generally useful (Was Re: Patches to use pydb instead of pdb for debugging)
rocky at panix.com
Wed Oct 11 23:30:45 EDT 2006
Although I don't like talking to myself, since no one else has said
anything on this topic, I've been ploughing on and here's what I've
In order to make the object inspection routines more useful to an
application (like a debugger) which is run from ipython, in a test
version I've changed Magic._ofind to accept a namespace parameter.
The default is the current hard-coded list. Routines like _inspect,
pdoc, pdef, and pinfo have been modified to allow this optional
parameter. Having done this, the debugger routine becomes
def do_pinfo(self, arg):
"""The debugger (or any application) equivalant of ?obj"""
namespaces = [('Locals', self.curframe.f_locals),
__IPYTHON__.magic_pinfo("pinfo %s" % arg, namespaces=namespaces)
and similarly for do_pdef, and do_pdoc. Overall, pretty simple.
Personally, I think a better organization though would be to pull out
the object inspection routines and make them their own class. The fact
that they are glommed with other routines like magic_lsmagic or
magic_autocall are just artifacts the current ipython interface naming
R. Bernstein writes:
> I was not have been clear on what I was hoping to do.
> Let's say I'm inside the debugger and I want to get the equivalent
> information for a local object "a" that I would get were I in the
> shell with that variable defined and were I to type "a?".
> And let's forget about how to handle the syntax of ? or ??. So let's
> add a new debugger command called "pinfo". All it wants to do is call
> Magic.magic_pinfo(), but somehow set up the local and global
> namespaces correctly. One could add to Debugger.py the following
> method which sort of works, but really isn't right. It hackily
> modifies one of the dictionaries that gets used via Magic.magic_pinfo.
> def do_pinfo(self, arg):
> """Sort of The debugger equivalant of obj? for a local variable"""
> # Find a dictionary to smack before the call. We'll use the
> # alias table.
> old_ns = __IPYTHON__.shell.alias_table # save
> __IPYTHON__.shell.alias_table = self.curframe.f_locals # smack
> __IPYTHON__.magic_pinfo("pinfo %s" % arg)
> __IPYTHON__.shell.alias_table = old_ns # restore
> Possibly the alias table shouldn't be wiped out -- I don't know
> possibly it is irrelevant in this context anyway. And the alias table
> is searched last whereas local variables are searched first by Python.
> Instead I think one would like a variant of Magic._ofind which has a
> notion of a local and global name spaces separate from the shell's
> namespace and some way for a debugger to hook in the current
> local/global namespaces to that. (Could the global namespace replace
> user_ns of the shell? Maybe, I don't know.)
> Note that such a routine as do_pinfo really has nothing to do with
> pydb at all. Short of finding incidental misfeatures in pdb (or pydb
> as I've been finding) which prevent this, to first approximation it
> should work equally well in both. Or any debugger; or any user
> application called from the ipython shell that want's to interact with
> ipython for that matter.
> - - -
> As a related but separate problem, now that I've go a way to invoke
> the debugger in full generaltity from ipython I'd also like to be able
> run such a "pinfo" command from that. By virtue of starting inside
> ipython I have all of the ipython routines around. In particular I
> have __IPYTHON__ defined. So moving that same do_pinfo routine from
> Debugger.py into someplace inside pydb's code would roughly do the
> same thing. But again, that code is really fairly wrong for the same
> Ville M. Vainio writes:
> > On 10/6/06, R. Bernstein <rocky at panix.com> wrote:
> > > ??object here). This could either be done inside pydb code, but maybe
> > > it would be neater to do inside ipython since it looks like there are
> > > routines already for decorating debugger commands. Suggestions on
> > > where to look to hook into '?' and '??'?
> > Now they are handled by "handle_help" in iplib.py, but you should
> > create an input_prefilter hook function that catches the ? commands
> > and translates them to something you want, e.g. ??foo ->
> > _pydb.detailedhelpcommand("foo"). see ext_rescapture.py on how to
> > implement one.
> > --
> > Ville M. Vainio - vivainio.googlepages.com
> > blog=360.yahoo.com/villevainio - g[mail | talk]='vivainio'
> IPython-dev mailing list
> IPython-dev at scipy.org
More information about the IPython-dev