Irit Katriel <iritkatr...@yahoo.com> added the comment:

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!
---------------------
---------------------------------------

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue34463>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to