Skip to content

bpo-24048: Save the live exception during import.c's remove_module() #13005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Save the live exception during import.c's ``remove_module()``.
10 changes: 7 additions & 3 deletions Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, it would be nice to chain the two exceptions rather than calling the nasty Py_FatalError() function :-(

}
out:
PyErr_Restore(type, value, traceback);
}


Expand Down