Skip to content

Commit a679c3d

Browse files
authored
gh-102799: replace sys.exc_info by sys.exception in inspect and traceback modules (#104032)
1 parent 2a884ce commit a679c3d

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

Lib/inspect.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,9 @@ def stack(context=1):
17661766

17671767
def trace(context=1):
17681768
"""Return a list of records for the stack below the current exception."""
1769-
return getinnerframes(sys.exc_info()[2], context)
1769+
exc = sys.exception()
1770+
tb = None if exc is None else exc.__traceback__
1771+
return getinnerframes(tb, context)
17701772

17711773

17721774
# ------------------------------------------------ static version of getattr

Lib/traceback.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ def _safe_string(value, what, func=str):
179179
# --
180180

181181
def print_exc(limit=None, file=None, chain=True):
182-
"""Shorthand for 'print_exception(*sys.exc_info(), limit, file, chain)'."""
183-
print_exception(*sys.exc_info(), limit=limit, file=file, chain=chain)
182+
"""Shorthand for 'print_exception(sys.exception(), limit, file, chain)'."""
183+
print_exception(sys.exception(), limit=limit, file=file, chain=chain)
184184

185185
def format_exc(limit=None, chain=True):
186186
"""Like print_exc() but return a string."""
187-
return "".join(format_exception(*sys.exc_info(), limit=limit, chain=chain))
187+
return "".join(format_exception(sys.exception(), limit=limit, chain=chain))
188188

189189
def print_last(limit=None, file=None, chain=True):
190190
"""This is a shorthand for 'print_exception(sys.last_exc, limit, file, chain)'."""

0 commit comments

Comments
 (0)