IDLE mini-hack & ?

Fredrik Lundh fredrik at pythonware.com
Thu Jul 22 07:10:27 EDT 1999


Greg Ewing <greg.ewing at compaq.com> wrote:
> Could the traceback printing thingy perhaps be
> enhanced to go just a little bit further down the
> chain and report the filename/linenumber of the
> function being called, not just the line it was
> being called from?

agreed.  but the problem is of course that
"apply" never completes the call, so the
offending function never appears on the
frame stack.

...

one solution could be to add the missing
information to the TypeError description
string, in a few places in ceval.c. like this:

1. add a support function to ceval.c which
takes a code object and an error message
(and possibly an exception object).

2. let this function combine the message
with the filename, linenumber, and function
name (if any) from the code object into a
message string, and call PyErr_SetString
with the result.

for details on how to get the names and
numbers, see code_repr in compile.c. you
might wish to add a support function to
compile.c for this purpose, maybe some-
thing like:

int PyCode_Describe(co, &filename, &lineno, &name)

or maybe you could cheat and use PyObject_Repr
to get the code object descriptor...

3. change the calls to PyErr_Format(TypeError)
and PyErr_SetString(TypeError) in compile.c, to
use this support function instead.

4. test it carefully, and submit patches to GvR.

...

an easier solution is to simply leave the offending
frame on the stack (it's there when the error is
detected). not sure about the side effects of
that solution, though...

</F>





More information about the Python-list mailing list