[Python-3000] Exception tracebacks and PEP 3101
pmaupin at gmail.com
Tue Mar 6 04:28:04 CET 2007
I'm a newbie when it comes to deep Python internals, so maybe I'm
missing something obvious. I'm trying to figure out the right answer
for exceptions/tracebacks in PEP 3101 (advanced string formatting).
Because the PEP 3101 string formatting is so much more powerful than
the existing %s, it seems that users will be much more tempted to
write large strings with complicated expressions inside them. When an
exception is thrown and the user needs to debug such a string, it
would be very useful to be able to show the user line number/character
information for the failing location inside the format string itself.
(The utility of this cannot be overstated -- I believe it will make or
break the out-of-the-box experience for this new feature for many
But because Python is so dynamic, if an exception is thrown during an
attribute or index operation during a call to the format() function,
the exception _might_ be because of something several execution frames
deep into the attribute operation, and it might be useful to show the
traceback stack to the user.
However, it seems that the Python traceback scheme is intimately tied
to the concept of Python execution frames, which are assumed to have
associated text information from a file. I'm not sure that I can
legitimately add to a preexisting traceback from a C function in a
non-fragile fashion. Even if I could, I don't really have a "file" to
show the user (unless I dynamically create one).
So it seems the only answer might have to have options like "let the
user see the existing traceback" or "get rid of the traceback and
raise an exception which shows exactly where in
the format string the error occured", or "print the preexisting
traceback to stderr, then toast it and raise a new exception showing
the string location in the exception text."
I guess there are two parts to my question:
1) What is the best thing to do right now for PEP3101?
2) If the "right now" answer isn't very good, is this really a more
general problem that needs work? As more "little languages" do things
like manipulate the AST, it might become very useful to have the
ability to place almost arbitrary objects on the traceback stack.
More information about the Python-3000