Message381488
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!
---------------------
--------------------------------------- |
|
Date |
User |
Action |
Args |
2020-11-20 16:32:35 | iritkatriel | set | recipients:
+ iritkatriel, Timothy McCurrach |
2020-11-20 16:32:35 | iritkatriel | set | messageid: <1605889955.96.0.356171249657.issue34463@roundup.psfhosted.org> |
2020-11-20 16:32:35 | iritkatriel | link | issue34463 messages |
2020-11-20 16:32:35 | iritkatriel | create | |
|