]> granicus.if.org Git - python/commitdiff
Set ImportError.name when raising the exception in the case of None
authorBrett Cannon <brett@python.org>
Sun, 15 Apr 2012 18:15:31 +0000 (14:15 -0400)
committerBrett Cannon <brett@python.org>
Sun, 15 Apr 2012 18:15:31 +0000 (14:15 -0400)
found in sys.modules.

Python/import.c

index 5136d98ac730a2d782ffa94dbc86ffd50d7a7342..d4f57835d30901cf895a59ffd20c6f0effe610dc 100644 (file)
@@ -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) {