[Python-3000] Putting pdb.set_trace() in builtins?
barry at python.org
Thu Feb 21 16:01:56 CET 2008
-----BEGIN PGP SIGNED MESSAGE-----
I know this will get shot down like a Navy missile aimed at an errant
spy satellite, but I'm going to suggest it anyway.
Several of us have been talking about merging the two Emacs Python
modes and this prompted a discussion of Ken Manheimer's excellent
pdbtrack hack, which got me thinking about the way I use pdb. I don't
know if this is typical or unique, or whether anyone else is annoyed
the same way I am. Admittedly it's a minor annoyance, but I still
think we can do better.
So I have some particularly troublesome code that I want to set a
breakpoint at and start stepping through. I usually will stick this
tidbit at the place I want to break:
import pdb; pdb.set_trace()
In doctests it's a little ickier because I have to put that all on the
line where I want to break, not before it or doctest won't do the
right thing, e.g.:
>>> import pdb; pdb.set_trace(); call_buggy_code()
I suggest that setting a breakpoint be done with a new built-in, e.g
breakpoint(). So now I would do this:
>>> breakpoint(); call_buggy_code()
Yes, all it saves me is an import, but it also elevates debugging to a
more important, and more visible location.
Okay, so now that I've convinced you this is the most brilliant idea
this century <wink>, I'm really going to smoke some crack.
The other thing this should do is allow us to use different debuggers
if we wanted. Maybe today breakpoint() would call into pdb, but maybe
tomorrow we'll have a better debugger, or someone will have installed
a better debugger in site-packages (e.g. pydb). I would suggest that
breakpoint() consult an environment variable such as PYTHONDEBUGGER to
see which debugger to invoke (the first time in a session only of
course). Perhaps you could also set PYTHONDEBUGGER=ignore to noop any
and all calls to breakpoint. Maybe there's a python command line
switch to mirror $PYTHONDEBUGGER.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)
-----END PGP SIGNATURE-----
More information about the Python-3000