]> granicus.if.org Git - python/commit
Print the offending line of code in the traceback for SyntaxErrors
authorJeremy Hylton <jeremy@alum.mit.edu>
Wed, 28 Feb 2001 07:07:43 +0000 (07:07 +0000)
committerJeremy Hylton <jeremy@alum.mit.edu>
Wed, 28 Feb 2001 07:07:43 +0000 (07:07 +0000)
commit9f1b9932b87a6da14f2c010dfcf2ed08cb50b768
tree09e9969a45c9171d9bf85c2819c2d7656753d999
parente860f9b983568efad41ab8cc828a107cf2096cb4
Print the offending line of code in the traceback for SyntaxErrors
raised by the compiler.

XXX For now, text entered into the interactive intepreter is not
printed in the traceback.

Inspired by a patch from Roman Sulzhyk

compile.c:

Add helper fetch_program_text() that opens a file and reads until it
finds the specified line number.  The code is a near duplicate of
similar code in traceback.c.

Modify com_error() to pass two arguments to SyntaxError constructor,
where the second argument contains the offending text when possible.

Modify set_error_location(), now used only by the symtable pass, to
set the text attribute on existing exceptions.

pythonrun.c:

Change parse_syntax_error() to continue of the offset attribute of a
SyntaxError is None.  In this case, it sets offset to -1.

Move code from PyErr_PrintEx() into helper function
print_error_text().  In the helper, only print the caret for a
SyntaxError if offset > 0.
Python/compile.c
Python/pythonrun.c