This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: traceback.format_exception_only() and SyntaxError
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, rblank
Priority: normal Keywords:

Created on 2006-03-11 13:46 by rblank, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
testSyntaxError.py rblank, 2006-03-11 13:46 Test case for format_exception_only() output
SyntaxErr.py rblank, 2006-03-11 13:47 Module generating an IndentationError
traceback.patch rblank, 2006-03-11 13:51 Patch that corrects the problem
Messages (4)
msg27740 - (view) Author: Remy Blank (rblank) Date: 2006-03-11 13:46
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.
msg27741 - (view) Author: Remy Blank (rblank) Date: 2006-03-11 13:47
Logged In: YES 
user_id=568100

This file generates the IndentationError.
msg27742 - (view) Author: Remy Blank (rblank) Date: 2006-03-11 13:51
Logged In: YES 
user_id=568100

This patch makes both the output of the interpreter and the
output generated by format_exception_only() identical.
msg27743 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-03-31 15:59
Logged In: YES 
user_id=849994

Fixed in rev. 43486. Thanks!
History
Date User Action Args
2022-04-11 14:56:15adminsetgithub: 43015
2006-03-11 13:46:45rblankcreate