bpo-24048: Save the live exception during import.c's remove_module() … · python/cpython@5aa40e5 (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 |
---|---|---|
@@ -827,14 +827,18 @@ PyImport_AddModule(const char *name) | ||
827 | 827 | static void |
828 | 828 | remove_module(PyObject *name) |
829 | 829 | { |
830 | +PyObject *type, *value, *traceback; | |
831 | +PyErr_Fetch(&type, &value, &traceback); | |
830 | 832 | PyObject *modules = PyImport_GetModuleDict(); |
833 | +if (!PyMapping_HasKey(modules, name)) { | |
834 | + goto out; | |
835 | + } | |
831 | 836 | if (PyMapping_DelItem(modules, name) < 0) { |
832 | -if (!PyMapping_HasKey(modules, name)) { | |
833 | -return; | |
834 | - } | |
835 | 837 | Py_FatalError("import: deleting existing key in " |
836 | 838 | "sys.modules failed"); |
837 | 839 | } |
840 | +out: | |
841 | +PyErr_Restore(type, value, traceback); | |
838 | 842 | } |
839 | 843 | |
840 | 844 |