From: Brett Cannon Date: Sun, 15 Apr 2012 18:15:31 +0000 (-0400) Subject: Set ImportError.name when raising the exception in the case of None X-Git-Tag: v3.3.0a3~215 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=27fc52877ce3cabb2ed524ab0f40f8c8e3a45c18;p=python Set ImportError.name when raising the exception in the case of None found in sys.modules. --- diff --git a/Python/import.c b/Python/import.c index 5136d98ac7..d4f57835d3 100644 --- a/Python/import.c +++ b/Python/import.c @@ -2980,8 +2980,11 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *given_globals, mod = PyDict_GetItem(interp->modules, abs_name); if (mod == Py_None) { - PyErr_Format(PyExc_ImportError, - "import of %R halted; None in sys.modules", abs_name); + PyObject *msg = PyUnicode_FromFormat("import of %R halted; " + "None in sys.modules", abs_name); + if (msg != NULL) { + PyErr_SetFromImportErrorWithName(msg, abs_name); + } goto error_with_unlock; } else if (mod != NULL) {