From: Serhiy Storchaka Date: Thu, 15 Jun 2017 18:15:26 +0000 (+0300) Subject: [3.5] bpo-30626: Fix error handling in PyImport_Import(). (GH-2103) (#2222) X-Git-Tag: v3.5.4rc1~71 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=263dcc39daa74066c2b2fcb007a4bd4f7ec65073;p=python [3.5] bpo-30626: Fix error handling in PyImport_Import(). (GH-2103) (#2222) In rare circumstances PyImport_Import() could return NULL without raising an error. (cherry picked from commit 145541c) --- diff --git a/Python/import.c b/Python/import.c index ea8bc00a73..4f08d5ebb7 100644 --- a/Python/import.c +++ b/Python/import.c @@ -1806,9 +1806,13 @@ PyImport_Import(PyObject *module_name) Py_DECREF(r); modules = PyImport_GetModuleDict(); - r = PyDict_GetItem(modules, module_name); - if (r != NULL) + r = PyDict_GetItemWithError(modules, module_name); + if (r != NULL) { Py_INCREF(r); + } + else if (!PyErr_Occurred()) { + PyErr_SetObject(PyExc_KeyError, module_name); + } err: Py_XDECREF(globals);