fastapi / typer

Typer, build great CLIs. Easy to code. Based on Python type hints.
https://typer.tiangolo.com/
MIT License
15.66k stars 666 forks source link

fix: don't set excepthook unless pretty_exceptions_enable #1030

Open charmoniumQ opened 2 days ago

charmoniumQ commented 2 days ago

Previously, pretty_exceptions_enable means "set sys.excepthook to the default exception handler". This commit changes the interpretation to "simply don't change sys.excepthook at all". If it was the default handler before, it will remain the default handler. If it was a customized excepthook before, it will remain a customized excepthook.

This interpretation gives more control to users when pretty_exceptions_enable is False, while maintaining the same out-of-the-box experience for users who leave it at its default (True).

Since sys.excepthook is for uncaught exceptions, it will be read directly by humans, I don't expect this change to break any users of Typer. Most users would leave pretty_exceptions_enable to the default (True), and that behavior did not change at all in this commit.