summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2023-03-18 11:47:11 (GMT)
committerGitHub <noreply@github.com>2023-03-18 11:47:11 (GMT)
commite1e9bab0061e8d4bd7b94ed455f3bb7bf8633ae7 (patch)
tree8363c72cc70b34e06fed5c39d86ec99047613799 /Lib/idlelib
parent039714d00f147be4d018fa6aeaf174aad7e8fa32 (diff)
downloadcpython-e1e9bab0061e8d4bd7b94ed455f3bb7bf8633ae7.zip
cpython-e1e9bab0061e8d4bd7b94ed455f3bb7bf8633ae7.tar.gz
cpython-e1e9bab0061e8d4bd7b94ed455f3bb7bf8633ae7.tar.bz2
gh-102778: Add sys.last_exc, deprecate sys.last_type, sys.last_value,sys.last_traceback (#102779)
Diffstat (limited to 'Lib/idlelib')
-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
4 files changed, 24 insertions, 9 deletions
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