[Python-checkins] bpo-24048: Save the live exception during import.c's remove_module() (GH-13005)
Miss Islington (bot)
webhook-mailer at python.org
Fri May 29 15:35:29 EDT 2020
https://github.com/python/cpython/commit/5aa40e587e63bcad22c7e196fc3559e2b5e0792b
commit: 5aa40e587e63bcad22c7e196fc3559e2b5e0792b
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2020-05-29T12:35:21-07:00
summary:
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 94a64e9cd411a87514b68082c1c437eb3b49dfb9)
Co-authored-by: Zackery Spytz <zspytz at gmail.com>
files:
A Misc/NEWS.d/next/Core and Builtins/2019-04-29-03-27-22.bpo-24048.vXxUDQ.rst
M Python/import.c
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 0000000000000..27c86a47f4b92
--- /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 6d014cf5b008f..d436d576eb3cd 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -827,14 +827,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);
}
More information about the Python-checkins
mailing list