summaryrefslogtreecommitdiff
path: root/Python
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2023-03-18 11:47:11 +0000
committerGitHub <noreply@github.com>2023-03-18 11:47:11 +0000
commite1e9bab0061e8d4bd7b94ed455f3bb7bf8633ae7 (patch)
tree8363c72cc70b34e06fed5c39d86ec99047613799 /Python
parent039714d00f147be4d018fa6aeaf174aad7e8fa32 (diff)
downloadcpython-git-e1e9bab0061e8d4bd7b94ed455f3bb7bf8633ae7.tar.gz
gh-102778: Add sys.last_exc, deprecate sys.last_type, sys.last_value,sys.last_traceback (#102779)
Diffstat (limited to 'Python')
-rw-r--r--Python/pylifecycle.c2
-rw-r--r--Python/pythonrun.c4
-rw-r--r--Python/sysmodule.c6
3 files changed, 9 insertions, 3 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index d0c65cc1f7..7bf12271db 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -1304,7 +1304,7 @@ finalize_modules_delete_special(PyThreadState *tstate, int verbose)
{
// List of names to clear in sys
static const char * const sys_deletes[] = {
- "path", "argv", "ps1", "ps2",
+ "path", "argv", "ps1", "ps2", "last_exc",
"last_type", "last_value", "last_traceback",
"__interactivehook__",
// path_hooks and path_importer_cache are cleared
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 07d119a678..6ea185a1b7 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -776,6 +776,10 @@ _PyErr_PrintEx(PyThreadState *tstate, int set_sys_last_vars)
}
if (set_sys_last_vars) {
+ if (_PySys_SetAttr(&_Py_ID(last_exc), exc) < 0) {
+ _PyErr_Clear(tstate);
+ }
+ /* Legacy version: */
if (_PySys_SetAttr(&_Py_ID(last_type), typ) < 0) {
_PyErr_Clear(tstate);
}
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index cc5b9a6d41..126b7d422e 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -2670,11 +2670,13 @@ stderr -- standard error object; used for error messages\n\
By assigning other file objects (or objects that behave like files)\n\
to these, it is possible to redirect all of the interpreter's I/O.\n\
\n\
+last_exc - the last uncaught exception\n\
+ Only available in an interactive session after a\n\
+ traceback has been printed.\n\
last_type -- type of last uncaught exception\n\
last_value -- value of last uncaught exception\n\
last_traceback -- traceback of last uncaught exception\n\
- These three are only available in an interactive session after a\n\
- traceback has been printed.\n\
+ These three are the (deprecated) legacy representation of last_exc.\n\
"
)
/* concatenating string here */