bpo-24048: Save the live exception during import.c's remove_module() … · python/cpython@94a64e9 (original) (raw)
File tree
2 files changed
lines changed
- Misc/NEWS.d/next/Core and Builtins
2 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1 | +Save the live exception during import.c's ``remove_module()``. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -837,14 +837,18 @@ PyImport_AddModule(const char *name) | ||
837 | 837 | static void |
838 | 838 | remove_module(PyObject *name) |
839 | 839 | { |
840 | +PyObject *type, *value, *traceback; | |
841 | +PyErr_Fetch(&type, &value, &traceback); | |
840 | 842 | PyObject *modules = PyImport_GetModuleDict(); |
843 | +if (!PyMapping_HasKey(modules, name)) { | |
844 | + goto out; | |
845 | + } | |
841 | 846 | if (PyMapping_DelItem(modules, name) < 0) { |
842 | -if (!PyMapping_HasKey(modules, name)) { | |
843 | -return; | |
844 | - } | |
845 | 847 | Py_FatalError("import: deleting existing key in " |
846 | 848 | "sys.modules failed"); |
847 | 849 | } |
850 | +out: | |
851 | +PyErr_Restore(type, value, traceback); | |
848 | 852 | } |
849 | 853 | |
850 | 854 |