Skip to content

Commit

Permalink
Restore source code printing in Python3 exception tracebacks
Browse files Browse the repository at this point in the history
Canonize tests

Restore source code printing in Python3 exception tracebacks

([arc::pullid] 413a9120-30fca745-5aba1da5-2d7bc890)

ref:7dd85c65460d342a8f1fd407ceba04b9d6c009b2
  • Loading branch information
borman committed Dec 24, 2018
1 parent 164742e commit db10198
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
15 changes: 14 additions & 1 deletion library/python/runtime_py3/importer.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,16 @@ class BuiltinSubmoduleImporter(BuiltinImporter):
return super().find_spec(fullname, None, target)
else:
return None



def excepthook(*args, **kws):
# traceback module cannot be imported at module level, because interpreter
# is not fully initialized yet

import traceback

return traceback.print_exception(*args, **kws)


sys.meta_path.insert(0, BuiltinSubmoduleImporter)

Expand All @@ -261,3 +270,7 @@ sys.frozen = True

# Set of names of importable modules.
sys.extra_modules = importer.memory

# Use custom implementation of traceback printer.
# Built-in printer (PyTraceBack_Print) does not support custom module loaders
sys.excepthook = excepthook
4 changes: 2 additions & 2 deletions library/python/runtime_py3/test/canondata/result.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"test_traceback.test_traceback[custom-default]": {
"stderr": {
"checksum": "26a06331e587d488b4fec501f09c7672",
"checksum": "6c1a9b47baa51cc6903b85fd43c529b5",
"uri": "file://test_traceback.test_traceback_custom-default_/stderr.txt"
},
"stdout": {
Expand Down Expand Up @@ -31,7 +31,7 @@
},
"test_traceback.test_traceback[main-default]": {
"stderr": {
"checksum": "26a06331e587d488b4fec501f09c7672",
"checksum": "6c1a9b47baa51cc6903b85fd43c529b5",
"uri": "file://test_traceback.test_traceback_main-default_/stderr.txt"
},
"stdout": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
Traceback (most recent call last):
File "library/python/runtime_py3/test/traceback/crash.py", line 44, in main
one()
File "library/python/runtime_py3/test/traceback/crash.py", line 12, in one
modfunc(two) # aaa
File "library/python/runtime_py3/test/traceback/mod/__init__.py", line 3, in modfunc
f() # call back to caller
File "library/python/runtime_py3/test/traceback/crash.py", line 16, in two
three(42)
File "library/python/runtime_py3/test/traceback/crash.py", line 20, in three
raise RuntimeError('Kaboom! I\'m dead: {}'.format(x))
RuntimeError: Kaboom! I'm dead: 42
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
Traceback (most recent call last):
File "library/python/runtime_py3/test/traceback/crash.py", line 44, in main
one()
File "library/python/runtime_py3/test/traceback/crash.py", line 12, in one
modfunc(two) # aaa
File "library/python/runtime_py3/test/traceback/mod/__init__.py", line 3, in modfunc
f() # call back to caller
File "library/python/runtime_py3/test/traceback/crash.py", line 16, in two
three(42)
File "library/python/runtime_py3/test/traceback/crash.py", line 20, in three
raise RuntimeError('Kaboom! I\'m dead: {}'.format(x))
RuntimeError: Kaboom! I'm dead: 42

0 comments on commit db10198

Please sign in to comment.