Issue 1447885: traceback.format_exception_only() and SyntaxError (original) (raw)

There is a special case in traceback.format_exception_only() for SyntaxError so that the location of the syntax error is printed. Unfortunately, the test is written so that it only works with SyntaxError, but not for children of SyntaxError, e.g. IndentationError.

OTOH, the interpreter prints the correct output if the exception is allowed to terminate the program.

I have attached a test case that shows the difference in output. With the current traceback.py module, the output is different:

joe@pat py $ ./testSyntaxError.py Traceback (most recent call last): File "./testSyntaxError.py", line 7, in ? import SyntaxErr IndentationError: expected an indented block (SyntaxErr.py, line 2)

joe@pat py $ ./testSyntaxError.py raise Traceback (most recent call last): File "./testSyntaxError.py", line 7, in ? import SyntaxErr File "/home/joe/tmp/py/SyntaxErr.py", line 2 class OtherClass: ^ IndentationError: expected an indented block

There's a second file that is needed for the test case, I'll attach it as well.