Skip to content

Commit 94a64e9

Browse files
ZackerySpytzncoghlan
authored andcommitted
bpo-24048: Save the live exception during import.c's remove_module() (GH-13005)
Save the live exception during the course of remove_module().
1 parent 85225b6 commit 94a64e9

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Save the live exception during import.c's ``remove_module()``.

Python/import.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -837,14 +837,18 @@ PyImport_AddModule(const char *name)
837837
static void
838838
remove_module(PyObject *name)
839839
{
840+
PyObject *type, *value, *traceback;
841+
PyErr_Fetch(&type, &value, &traceback);
840842
PyObject *modules = PyImport_GetModuleDict();
843+
if (!PyMapping_HasKey(modules, name)) {
844+
goto out;
845+
}
841846
if (PyMapping_DelItem(modules, name) < 0) {
842-
if (!PyMapping_HasKey(modules, name)) {
843-
return;
844-
}
845847
Py_FatalError("import: deleting existing key in "
846848
"sys.modules failed");
847849
}
850+
out:
851+
PyErr_Restore(type, value, traceback);
848852
}
849853

850854

0 commit comments

Comments
 (0)