From 4e06328bec6d853d0cc0cd692ea9f23cb5c42b40 Mon Sep 17 00:00:00 2001 From: Niraj Kulkarni Date: Thu, 4 Jul 2024 14:07:55 +0530 Subject: [PATCH] Rewrited deprecated in `print_exception` (#5407) * Change deprecated sys variable assignment in print_exception * Add changelog in news/print_exception_fix.rst --- news/print_exception_fix.rst | 23 +++++++++++++++++++++++ xonsh/tools.py | 4 ++-- 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 news/print_exception_fix.rst diff --git a/news/print_exception_fix.rst b/news/print_exception_fix.rst new file mode 100644 index 000000000..a0807ac81 --- /dev/null +++ b/news/print_exception_fix.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* Replaced deprecated `sys.last_type, sys.last_value, sys.last_traceback` with `sys.last_exc` + +**Security:** + +* diff --git a/xonsh/tools.py b/xonsh/tools.py index c8bff91a4..3f466ec54 100644 --- a/xonsh/tools.py +++ b/xonsh/tools.py @@ -1025,7 +1025,7 @@ def print_warning(msg): def print_exception(msg=None, exc_info=None, source_msg=None): - """Print given exception (or current if None) with/without traceback and set sys.last_type, sys.last_value, sys.last_traceback accordingly.""" + """Print given exception (or current if None) with/without traceback and set sys.last_exc accordingly.""" # is no exec_info() triple is given, use the exception beeing handled at the moment if exc_info is None: @@ -1055,7 +1055,7 @@ def print_exception(msg=None, exc_info=None, source_msg=None): limit = 0 chain = False - sys.last_type, sys.last_value, sys.last_traceback = exc_info + sys.last_exc = exc_info manually_set_trace, show_trace = _get_manual_env_var("XONSH_SHOW_TRACEBACK", False) manually_set_logfile, log_file = _get_manual_env_var("XONSH_TRACEBACK_LOGFILE")