Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tback: make Traceback printing compatible with Python 3 #246

Merged
merged 3 commits into from
Jan 16, 2024

Conversation

lzaoral
Copy link
Contributor

@lzaoral lzaoral commented Jan 12, 2024

Because kobo only supports Python 3.6+, we can just return a
concatenated Unicode string with the given exception.

Fixes the following incorrectly formatted output:

$ cat test.py
from kobo.tback import set_except_hook
set_except_hook()

assert False

$ python3 test.py
b'Traceback (most recent call last):\n  File "/Users/lzaoral/redhat/OpenScanHub/kobo/test.py", line 4, in <module>\n    assert False\nAssertionError\nFrame <module> in /Users/lzaoral/redhat/OpenScanHub/kobo/test.py at line 4\n<CODE>\n       1 from kobo.tback import set_except_hook\n       2 set_except_hook()\n       3 \n-->    4 assert False\n</CODE>\n<LOCALS>\n     __annotations__ = {}\n        __builtins__ = <module \'builtins\' (built-in)>\n          __cached__ = None\n             __doc__ = None\n            __file__ = \'/Users/lzaoral/redhat/OpenScanHub/kobo/test.py\'\n          __loader__ = <_frozen_importlib_external.SourceFileLoader object at 0x100711650>\n            __name__ = \'__main__\'\n         __package__ = None\n            __spec__ = None\n     set_except_hook = <function set_except_hook at 0x10082df80>\n</LOCALS>\n'

Because kobo only supports Python 3.6+, we can just return a
concatenated unicode string with the given exception.

Fixes the following incorrectly formatted output:
```
$ cat test.py
from kobo.tback import set_except_hook
set_except_hook()

assert False

$ python3 test.py
b'Traceback (most recent call last):\n  File "/Users/lzaoral/redhat/OpenScanHub/kobo/test.py", line 4, in <module>\n    assert False\nAssertionError\nFrame <module> in /Users/lzaoral/redhat/OpenScanHub/kobo/test.py at line 4\n<CODE>\n       1 from kobo.tback import set_except_hook\n       2 set_except_hook()\n       3 \n-->    4 assert False\n</CODE>\n<LOCALS>\n     __annotations__ = {}\n        __builtins__ = <module \'builtins\' (built-in)>\n          __cached__ = None\n             __doc__ = None\n            __file__ = \'/Users/lzaoral/redhat/OpenScanHub/kobo/test.py\'\n          __loader__ = <_frozen_importlib_external.SourceFileLoader object at 0x100711650>\n            __name__ = \'__main__\'\n         __package__ = None\n            __spec__ = None\n     set_except_hook = <function set_except_hook at 0x10082df80>\n</LOCALS>\n'
```
`Traceback.get_traceback` no longer produces broken output.  Therefore, our
reimplementation of `xmlrpc.client.Fault.__repr__` can be greatly simplified.
@rohanpm rohanpm merged commit df8fb01 into release-engineering:master Jan 16, 2024
19 checks passed
@lzaoral lzaoral deleted the fix-traceback-format branch January 16, 2024 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants