summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/code.py4
-rw-r--r--Lib/dis.py5
-rw-r--r--Lib/idlelib/idle_test/test_stackviewer.py3
-rwxr-xr-xLib/idlelib/pyshell.py7
-rw-r--r--Lib/idlelib/run.py2
-rw-r--r--Lib/idlelib/stackviewer.py21
-rwxr-xr-xLib/pdb.py6
-rw-r--r--Lib/pydoc_data/topics.py4
-rw-r--r--Lib/test/test_dis.py10
-rw-r--r--Lib/test/test_ttk/test_extensions.py4
-rw-r--r--Lib/tkinter/__init__.py1
-rw-r--r--Lib/traceback.py16
12 files changed, 61 insertions, 22 deletions
diff --git a/Lib/code.py b/Lib/code.py
index 76000f8..2bd5fa3 100644
--- a/Lib/code.py
+++ b/Lib/code.py
@@ -106,6 +106,7 @@ class InteractiveInterpreter:
"""
type, value, tb = sys.exc_info()
+ sys.last_exc = value
sys.last_type = type
sys.last_value = value
sys.last_traceback = tb
@@ -119,7 +120,7 @@ class InteractiveInterpreter:
else:
# Stuff in the right filename
value = SyntaxError(msg, (filename, lineno, offset, line))
- sys.last_value = value
+ sys.last_exc = sys.last_value = value
if sys.excepthook is sys.__excepthook__:
lines = traceback.format_exception_only(type, value)
self.write(''.join(lines))
@@ -138,6 +139,7 @@ class InteractiveInterpreter:
"""
sys.last_type, sys.last_value, last_tb = ei = sys.exc_info()
sys.last_traceback = last_tb
+ sys.last_exc = ei[1]
try:
lines = traceback.format_exception(ei[0], ei[1], last_tb.tb_next)
if sys.excepthook is sys.__excepthook__:
diff --git a/Lib/dis.py b/Lib/dis.py
index 9edde6a..c3d152b 100644
--- a/Lib/dis.py
+++ b/Lib/dis.py
@@ -118,7 +118,10 @@ def distb(tb=None, *, file=None, show_caches=False, adaptive=False):
"""Disassemble a traceback (default: last traceback)."""
if tb is None:
try:
- tb = sys.last_traceback
+ if hasattr(sys, 'last_exc'):
+ tb = sys.last_exc.__traceback__
+ else:
+ tb = sys.last_traceback
except AttributeError:
raise RuntimeError("no last traceback to disassemble") from None
while tb.tb_next: tb = tb.tb_next
diff --git a/Lib/idlelib/idle_test/test_stackviewer.py b/Lib/idlelib/idle_test/test_stackviewer.py
index 98f53f9..f4626bb 100644
--- a/Lib/idlelib/idle_test/test_stackviewer.py
+++ b/Lib/idlelib/idle_test/test_stackviewer.py
@@ -19,6 +19,7 @@ class StackBrowserTest(unittest.TestCase):
except NameError:
svs.last_type, svs.last_value, svs.last_traceback = (
sys.exc_info())
+ svs.last_exc = svs.last_value
requires('gui')
cls.root = Tk()
@@ -27,7 +28,7 @@ class StackBrowserTest(unittest.TestCase):
@classmethod
def tearDownClass(cls):
svs = stackviewer.sys
- del svs.last_traceback, svs.last_type, svs.last_value
+ del svs.last_exc, svs.last_traceback, svs.last_type, svs.last_value
cls.root.update_idletasks()
## for id in cls.root.tk.call('after', 'info'):
diff --git a/Lib/idlelib/pyshell.py b/Lib/idlelib/pyshell.py
index e68233a..edc77ff 100755
--- a/Lib/idlelib/pyshell.py
+++ b/Lib/idlelib/pyshell.py
@@ -1367,11 +1367,14 @@ class PyShell(OutputWindow):
if self.interp.rpcclt:
return self.interp.remote_stack_viewer()
try:
- sys.last_traceback
+ if hasattr(sys, 'last_exc'):
+ sys.last_exc.__traceback__
+ else:
+ sys.last_traceback
except:
messagebox.showerror("No stack trace",
"There is no stack trace yet.\n"
- "(sys.last_traceback is not defined)",
+ "(sys.last_exc and sys.last_traceback are not defined)",
parent=self.text)
return
from idlelib.stackviewer import StackBrowser
diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py
index 577c49e..6a7b50c 100644
--- a/Lib/idlelib/run.py
+++ b/Lib/idlelib/run.py
@@ -239,6 +239,7 @@ def print_exception():
efile = sys.stderr
typ, val, tb = excinfo = sys.exc_info()
sys.last_type, sys.last_value, sys.last_traceback = excinfo
+ sys.last_exc = val
seen = set()
def print_exc(typ, exc, tb):
@@ -629,6 +630,7 @@ class Executive:
flist = self.rpchandler.get_remote_proxy(flist_oid)
while tb and tb.tb_frame.f_globals["__name__"] in ["rpc", "run"]:
tb = tb.tb_next
+ sys.last_exc = val
sys.last_type = typ
sys.last_value = val
item = stackviewer.StackTreeItem(flist, tb)
diff --git a/Lib/idlelib/stackviewer.py b/Lib/idlelib/stackviewer.py
index 94ffb4e..702fd32 100644
--- a/Lib/idlelib/stackviewer.py
+++ b/Lib/idlelib/stackviewer.py
@@ -27,7 +27,10 @@ class StackTreeItem(TreeItem):
def get_stack(self, tb):
if tb is None:
- tb = sys.last_traceback
+ if hasattr(sys, 'last_exc'):
+ tb = sys.last_exc.__traceback__
+ else:
+ tb = sys.last_traceback
stack = []
if tb and tb.tb_frame is None:
tb = tb.tb_next
@@ -37,11 +40,15 @@ class StackTreeItem(TreeItem):
return stack
def get_exception(self):
- type = sys.last_type
- value = sys.last_value
- if hasattr(type, "__name__"):
- type = type.__name__
- s = str(type)
+ if hasattr(sys, 'last_exc'):
+ typ = type(sys.last_exc)
+ value = sys.last_exc
+ else:
+ typ = sys.last_type
+ value = sys.last_value
+ if hasattr(typ, "__name__"):
+ typ = typ.__name__
+ s = str(typ)
if value is not None:
s = s + ": " + str(value)
return s
@@ -136,6 +143,7 @@ def _stack_viewer(parent): # htest #
except NameError:
exc_type, exc_value, exc_tb = sys.exc_info()
# inject stack trace to sys
+ sys.last_exc = exc_value
sys.last_type = exc_type
sys.last_value = exc_value
sys.last_traceback = exc_tb
@@ -143,6 +151,7 @@ def _stack_viewer(parent): # htest #
StackBrowser(top, flist=flist, top=top, tb=exc_tb)
# restore sys to original state
+ del sys.last_exc
del sys.last_type
del sys.last_value
del sys.last_traceback
diff --git a/Lib/pdb.py b/Lib/pdb.py
index f11fc55..3543f53 100755
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -1739,7 +1739,11 @@ def post_mortem(t=None):
def pm():
"""Enter post-mortem debugging of the traceback found in sys.last_traceback."""
- post_mortem(sys.last_traceback)
+ if hasattr(sys, 'last_exc'):
+ tb = sys.last_exc.__traceback__
+ else:
+ tb = sys.last_traceback
+ post_mortem(tb)
# Main program for testing
diff --git a/Lib/pydoc_data/topics.py b/Lib/pydoc_data/topics.py
index 573065b..ad1b6ac 100644
--- a/Lib/pydoc_data/topics.py
+++ b/Lib/pydoc_data/topics.py
@@ -4799,7 +4799,7 @@ topics = {'assert': 'The "assert" statement\n'
'pdb.pm()\n'
'\n'
' Enter post-mortem debugging of the traceback found in\n'
- ' "sys.last_traceback".\n'
+ ' "sys.last_exc".\n'
'\n'
'The "run*" functions and "set_trace()" are aliases for '
'instantiating\n'
@@ -13858,7 +13858,7 @@ topics = {'assert': 'The "assert" statement\n'
'if\n'
' the interpreter is interactive, it is also made available to '
'the\n'
- ' user as "sys.last_traceback".\n'
+ ' user as "sys.last_exc".\n'
'\n'
' For explicitly created tracebacks, it is up to the creator '
'of\n'
diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py
index b77e3b0..fa1de1c 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -1027,6 +1027,10 @@ class DisTests(DisTestBase):
def test_dis_none(self):
try:
+ del sys.last_exc
+ except AttributeError:
+ pass
+ try:
del sys.last_traceback
except AttributeError:
pass
@@ -1043,7 +1047,7 @@ class DisTests(DisTestBase):
1/0
except Exception as e:
tb = e.__traceback__
- sys.last_traceback = tb
+ sys.last_exc = e
tb_dis = self.get_disassemble_as_string(tb.tb_frame.f_code, tb.tb_lasti)
self.do_disassembly_test(None, tb_dis, True)
@@ -1901,6 +1905,10 @@ class TestFinderMethods(unittest.TestCase):
class TestDisTraceback(DisTestBase):
def setUp(self) -> None:
try: # We need to clean up existing tracebacks
+ del sys.last_exc
+ except AttributeError:
+ pass
+ try: # We need to clean up existing tracebacks
del sys.last_traceback
except AttributeError:
pass
diff --git a/Lib/test/test_ttk/test_extensions.py b/Lib/test/test_ttk/test_extensions.py
index 6135c49..d5e0697 100644
--- a/Lib/test/test_ttk/test_extensions.py
+++ b/Lib/test/test_ttk/test_extensions.py
@@ -45,7 +45,9 @@ class LabeledScaleTest(AbstractTkTest, unittest.TestCase):
# value which causes the tracing callback to be called and then
# it tries calling instance attributes not yet defined.
ttk.LabeledScale(self.root, variable=myvar)
- if hasattr(sys, 'last_type'):
+ if hasattr(sys, 'last_exc'):
+ self.assertNotEqual(type(sys.last_exc), tkinter.TclError)
+ elif hasattr(sys, 'last_type'):
self.assertNotEqual(sys.last_type, tkinter.TclError)
def test_initialization(self):
diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py
index 7565e0f..479daf0 100644
--- a/Lib/tkinter/__init__.py
+++ b/Lib/tkinter/__init__.py
@@ -2400,6 +2400,7 @@ class Tk(Misc, Wm):
should when sys.stderr is None."""
import traceback
print("Exception in Tkinter callback", file=sys.stderr)
+ sys.last_exc = val
sys.last_type = exc
sys.last_value = val
sys.last_traceback = tb
diff --git a/Lib/traceback.py b/Lib/traceback.py
index c43c472..9e720ac 100644
--- a/Lib/traceback.py
+++ b/Lib/traceback.py
@@ -179,7 +179,7 @@ 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)'."""
+ """Shorthand for 'print_exception(*sys.exc_info(), limit, file, chain)'."""
print_exception(*sys.exc_info(), limit=limit, file=file, chain=chain)
def format_exc(limit=None, chain=True):
@@ -187,12 +187,16 @@ def format_exc(limit=None, chain=True):
return "".join(format_exception(*sys.exc_info(), limit=limit, chain=chain))
def print_last(limit=None, file=None, chain=True):
- """This is a shorthand for 'print_exception(sys.last_type,
- sys.last_value, sys.last_traceback, limit, file)'."""
- if not hasattr(sys, "last_type"):
+ """This is a shorthand for 'print_exception(sys.last_exc, limit, file, chain)'."""
+ if not hasattr(sys, "last_exc") and not hasattr(sys, "last_type"):
raise ValueError("no last exception")
- print_exception(sys.last_type, sys.last_value, sys.last_traceback,
- limit, file, chain)
+
+ if hasattr(sys, "last_exc"):
+ print_exception(sys.last_exc, limit, file, chain)
+ else:
+ print_exception(sys.last_type, sys.last_value, sys.last_traceback,
+ limit, file, chain)
+
#
# Printing and Extracting Stacks.