"assert" annoyance

Paul Rubin http
Fri Jun 22 07:31:24 CEST 2007

So I have some assert statements in my code to verify the absence of
some "impossible" conditions.  They were useful in debugging and of
course I left them in place for "real" runs of the program.  Umpteen
hours into a run, an assertion failed, and of course since failure
was "impossible", I didn't catch the exception so the whole program
crashed.  I don't know what I'd have done with the exception anyway,
since it would have had to be caught at an outer scope where the
data I cared about was no longer around, or else I'd have had to
predict in advance what I needed to examine and pass that as a
an arg to the assert statement.

What I really want is for any assertion failure, anywhere in the
program, to trap to the debugger WITHOUT blowing out of the scope
where the failure happened, so I can examine the local frame.  That
just seems natural, but I don't see an obvious way to do it.  Am I
missing something?  I guess I could replace all the assertions with
function calls that launch pdb, but why bother having an assert

More information about the Python-list mailing list