mirror of
https://github.com/Textualize/rich.git
synced 2025-08-04 18:18:22 +00:00
Merge e97469577f
into b6aae7c342
This commit is contained in:
commit
4f8a710065
1 changed files with 26 additions and 2 deletions
|
@ -50,6 +50,7 @@ WINDOWS = sys.platform == "win32"
|
|||
|
||||
LOCALS_MAX_LENGTH = 10
|
||||
LOCALS_MAX_STRING = 80
|
||||
_UNINSTALL_CALLABLE = None
|
||||
|
||||
|
||||
def _iter_syntax_lines(
|
||||
|
@ -197,16 +198,39 @@ def install(
|
|||
*args, is_syntax=True, **kwargs
|
||||
)
|
||||
|
||||
global _UNINSTALL_CALLABLE
|
||||
try: # pragma: no cover
|
||||
# if within ipython, use customized traceback
|
||||
ip = get_ipython() # type: ignore[name-defined]
|
||||
old_hooks = [ip._showtraceback, ip.showtraceback, ip.showsyntaxerror]
|
||||
ipy_excepthook_closure(ip)
|
||||
return sys.excepthook
|
||||
|
||||
def _uninstall():
|
||||
# if within ipython, use customized traceback
|
||||
ip = get_ipython() # type: ignore[name-defined]
|
||||
ip._showtraceback = old_hooks[0]
|
||||
# add wrapper to capture tb_data
|
||||
ip.showtraceback = old_hooks[1]
|
||||
ip.showsyntaxerror = old_hooks[2]
|
||||
|
||||
_UNINSTALL_CALLABLE = _uninstall
|
||||
return _uninstall
|
||||
except Exception:
|
||||
# otherwise use default system hook
|
||||
old_excepthook = sys.excepthook
|
||||
sys.excepthook = excepthook
|
||||
return old_excepthook
|
||||
|
||||
def _uninstall():
|
||||
sys.excepthook = old_excepthook
|
||||
|
||||
_UNINSTALL_CALLABLE = _uninstall
|
||||
return _uninstall
|
||||
|
||||
|
||||
def uninstall() -> None:
|
||||
"""Reset any installed traceback or except hook(s) if any."""
|
||||
if _UNINSTALL_CALLABLE:
|
||||
_UNINSTALL_CALLABLE()
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue