[IPython-user] Colorizing lines in debuggers and post-mortem

R. Bernstein rocky@panix....
Wed Feb 14 14:21:18 CST 2007

When looking at the colorized debugger output, there something I think
a little odd. IPython has a colorize routine for Python programs.  I'm
referring to PyColorize.Parse.format here.  But format is not used in
these listings, even though IPython also has a customized debugger
"list" method.

I guess the problem has to do with getting *fragments* of Python which
you may get in a single line of Python code. The tokenization routine
might return an error. Note though that most Python code is properly
formatted when looked at on a line by line basis.

I think that if the format method's interface were changed slightly,
IPython could show program in debuggers and post-mortem
better. Instead of format writing to the output some sort of error
message when a line is malformed (or more likely incomplete), if it
returned an error status or raised an exception the caller could take
appropriate action.

Assuming a change like this, here's how I think a listing would
work. You call format on a line or range of lines, if that there's no
error you accept the formatted output. Otherwise you just print the
line as is (which is what is being done now).

Also, I've made a change in pydb CVS (just after the 1.21 release) so
that when running post-mortem or pm you can pass in a custom Pdb
object. IPython has a custom Pdb object which changes the way listing
and stack printing works. It uses this in other situations. With some
introspection (because most version right now of pdb and pydb don't
support passing in a Pdb object in post-mortem), IPython could also
pass such a debugger object.

More information about the IPython-user mailing list