Author iritkatriel
Recipients Timothy McCurrach, iritkatriel
Date 2020-11-20.16:32:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1605889955.96.0.356171249657.issue34463@roundup.psfhosted.org>
In-reply-to
Content
After debugging the default excepthook code (C version), I see that the difference is because the SyntaxError's lineno is None. 

It doesn't mind that the filename is None (it defaults it to <string>) but when it can't get the lineno it gives up here:
https://github.com/python/cpython/blob/fb5db7ec58624cab0797b4050735be865d380823/Python/pythonrun.c#L481

If you run this script:

---------------------------------------
import traceback
import sys

se = SyntaxError("wrong!")
se.filename = "myfile.py"
print("========== lineno is None ==========")
print('traceback.print_exception:')
traceback.print_exception(type(se), se, None)
print('---------------------')
print('sys.excepthook:')
sys.excepthook(type(se), se, None)
print('---------------------')

se.lineno = 55

print("========== lineno is 55 ==========")
print('traceback.print_exception:')
traceback.print_exception(type(se), se, None)
print('---------------------')
print('sys.excepthook:')
sys.excepthook(type(se), se, None)
print('---------------------')

---------------------------------------


The output is:
---------------------------------------
Running Release|x64 interpreter...
========== lineno is None ==========
traceback.print_exception:
  File "myfile.py", line None
SyntaxError: wrong!
---------------------
sys.excepthook:                   <-- file-lineno missing
SyntaxError: wrong! (myfile.py)
---------------------
========== lineno is 55 ==========
traceback.print_exception:
  File "myfile.py", line 55
SyntaxError: wrong!
---------------------
sys.excepthook:
  File "myfile.py", line 55       <-- file-lineno is there
SyntaxError: wrong!
---------------------
---------------------------------------
History
Date User Action Args
2020-11-20 16:32:35iritkatrielsetrecipients: + iritkatriel, Timothy McCurrach
2020-11-20 16:32:35iritkatrielsetmessageid: <1605889955.96.0.356171249657.issue34463@roundup.psfhosted.org>
2020-11-20 16:32:35iritkatriellinkissue34463 messages
2020-11-20 16:32:35iritkatrielcreate