8000 bpo-24048: Save the live exception during import.c's remove_module() … · python/cpython@5aa40e5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5aa40e5

Browse files
bpo-24048: Save the live exception during import.c's remove_module() (GH-13005)
Save the live exception during the course of remove_module(). (cherry picked from commit 94a64e9) Co-authored-by: Zackery Spytz <zspytz@gmail.com>
1 parent 852e8a7 commit 5aa40e5

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
@@ -827,14 +827,18 @@ PyImport_AddModule(const char *name)
827827
static void
828828
remove_module(PyObject *name)
829829
{
830+
PyObject *type, *value, *traceback;
831+
PyErr_Fetch(&type, &value, &traceback);
830832
PyObject *modules = PyImport_GetModuleDict();
833+
if (!PyMapping_HasKey(modules, name)) {
834+
goto out;
835+
}
831836
if (PyMapping_DelItem(modules, name) < 0) {
832-
if (!PyMapping_HasKey(modules, name)) {
833-
return;
834-
}
835837
Py_FatalError("import: deleting existing key in "
836838
"sys.modules failed");
837839
}
840+
out:
841+
PyErr_Restore(type, value, traceback);
838842
}
839843

840844

0 commit comments

Comments
 (0)
0