[New-bugs-announce] [issue19146] Improvements to traceback module

Guido van Rossum report at bugs.python.org
Wed Oct 2 19:03:01 CEST 2013

New submission from Guido van Rossum:

The traceback module is driving me nuts.  It has some handy helpers to extract info about a traceback or a full stack without formatting them, but (a) these are _internal, and (b) they don't return the frame object as part of the information, so code that wants to do additional stuff (e.g. print the values of local variables) cannot use them. (I guess in a sense the two problems cancel each other out. :-)

Here's a proposed fix.  (I know it is lacking tests.)

It adds extract_tb_ex() and extract_stack_ex() functions that return a list of 5-tuples filename, line number, function name, text, frame).

I'm also reworking the lowest-level internal function, _extract_tb_or_stack_iter(), to take an iterator instead of a starting point and a function to get the info and the next starting point.  The old design feels unpythonic to me -- the task at hand so clearly feels like it should wrap an iterator!

Finally, I'm adding some important info to a few docstrings: when the limit clips the number of frames, you get the *oldest* frames from a traceback, but the *newest* frames from a stack. That makes sense when you think about it, but I still think it's worth mentioning.


messages: 198852
nosy: akuchling, benjamin.peterson, gvanrossum
priority: normal
severity: normal
status: open
title: Improvements to traceback module

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list