diff options
-rw-r--r-- | Misc/NEWS.d/next/Core and Builtins/2019-04-29-03-27-22.bpo-24048.vXxUDQ.rst | 1 | ||||
-rw-r--r-- | Python/import.c | 10 |
2 files changed, 8 insertions, 3 deletions
diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-04-29-03-27-22.bpo-24048.vXxUDQ.rst b/Misc/NEWS.d/next/Core and Builtins/2019-04-29-03-27-22.bpo-24048.vXxUDQ.rst new file mode 100644 index 0000000..27c86a4 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2019-04-29-03-27-22.bpo-24048.vXxUDQ.rst @@ -0,0 +1 @@ +Save the live exception during import.c's ``remove_module()``. diff --git a/Python/import.c b/Python/import.c index b03bc98..9290f39 100644 --- a/Python/import.c +++ b/Python/import.c @@ -837,14 +837,18 @@ PyImport_AddModule(const char *name) static void remove_module(PyObject *name) { + PyObject *type, *value, *traceback; + PyErr_Fetch(&type, &value, &traceback); PyObject *modules = PyImport_GetModuleDict(); + if (!PyMapping_HasKey(modules, name)) { + goto out; + } if (PyMapping_DelItem(modules, name) < 0) { - if (!PyMapping_HasKey(modules, name)) { - return; - } Py_FatalError("import: deleting existing key in " "sys.modules failed"); } +out: + PyErr_Restore(type, value, traceback); } |