First Check
Commit to Help
Example Code
import sys
import os
from typer import run
def main():
raise RuntimeError()
def hook_example(*_):
orig_hook(*_)
print("Hook called")
orig_hook = sys.excepthook
sys.excepthook = hook_example
os.environ["_TYPER_STANDARD_TRACEBACK"] = "true"
if __name__ == '__main__':
run(main)
Description
- I am trying to have my own
sys.excepthook override, not typer's one
- The example code posted does not fire
hook_example()
- The way typer sets up it's own excepthook makes this difficult, the only way to make it work is to ensure you have replaced
sys.excepthook before typer is imported which is difficult not get right and a difficult to not break when refactoring
- The reason is typer stores
_original_except_hook = sys.excepthook at it's top level in main.py but does not replace sys.excepthook until it's actually called
- IMHO what should happen instead:
- typer should store the original hook at the time it replaces it
- There should be a programatic way to disable typer's excepthook override (not just through an env var)
- I am happy to do the PR for this
Operating System
Linux, macOS
Operating System Details
No response
Typer Version
0.6.1
Python Version
3.8.13
Additional Context
No response
First Check
Commit to Help
Example Code
Description
sys.excepthookoverride, not typer's onehook_example()sys.excepthookbefore typer is imported which is difficult not get right and a difficult to not break when refactoring_original_except_hook = sys.excepthookat it's top level inmain.pybut does not replacesys.excepthookuntil it's actually calledOperating System
Linux, macOS
Operating System Details
No response
Typer Version
0.6.1
Python Version
3.8.13
Additional Context
No response