8000 bpo-30626: Fix error handling in PyImport_Import(). (#2103) · python/cpython@145541c · GitHub
[go: up one dir, main page]

Skip to content

Commit 145541c

Browse files
bpo-30626: Fix error handling in PyImport_Import(). (#2103)
In rare circumstances PyImport_Import() could return NULL without raising an error.
1 parent 96c7c06 commit 145541c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Python/import.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,9 +1784,13 @@ PyImport_Import(PyObject *module_name)
17841784
Py_DECREF(r);
17851785

17861786
modules = PyImport_GetModuleDict();
1787-
r = PyDict_GetItem(modules, module_name);
1788-
if (r != NULL)
1787+
r = PyDict_GetItemWithError(modules, module_name);
1788+
if (r != NULL) {
17891789
Py_INCREF(r);
1790+
}
1791+
else if (!PyErr_Occurred()) {
1792+
PyErr_SetObject(PyExc_KeyError, module_name);
1793+
}
17901794

17911795
err:
17921796
Py_XDECREF(globals);

0 commit comments

Comments
 (0)
0