]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-102799: replace sys.exc_info by sys.exception in inspect and traceback modules...
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>
Mon, 1 May 2023 17:19:47 +0000 (18:19 +0100)
committerGitHub <noreply@github.com>
Mon, 1 May 2023 17:19:47 +0000 (18:19 +0100)
Lib/inspect.py
Lib/traceback.py

index 6d1d7b766cb3bb615544f1f1ccd262adb0775ed9..92c2675cfd7d32d3191d398f36a5a7a517e399fa 100644 (file)
@@ -1766,7 +1766,9 @@ def stack(context=1):
 
 def trace(context=1):
     """Return a list of records for the stack below the current exception."""
-    return getinnerframes(sys.exc_info()[2], context)
+    exc = sys.exception()
+    tb = None if exc is None else exc.__traceback__
+    return getinnerframes(tb, context)
 
 
 # ------------------------------------------------ static version of getattr
index ba4a9ffd001b53e8f975dc39cb395b1dae8cd927..419f6e81b5e1be986a642a39bc8adecb3d6b6242 100644 (file)
@@ -179,12 +179,12 @@ def _safe_string(value, what, func=str):
 # --
 
 def print_exc(limit=None, file=None, chain=True):
-    """Shorthand for 'print_exception(*sys.exc_info(), limit, file, chain)'."""
-    print_exception(*sys.exc_info(), limit=limit, file=file, chain=chain)
+    """Shorthand for 'print_exception(sys.exception(), limit, file, chain)'."""
+    print_exception(sys.exception(), limit=limit, file=file, chain=chain)
 
 def format_exc(limit=None, chain=True):
     """Like print_exc() but return a string."""
-    return "".join(format_exception(*sys.exc_info(), limit=limit, chain=chain))
+    return "".join(format_exception(sys.exception(), limit=limit, chain=chain))
 
 def print_last(limit=None, file=None, chain=True):
     """This is a shorthand for 'print_exception(sys.last_exc, limit, file, chain)'."""