[Python-checkins] cpython: Set ImportError.name when raising the exception in the case of None

brett.cannon python-checkins at python.org
Sun Apr 15 21:25:22 CEST 2012


http://hg.python.org/cpython/rev/c9fb9f5e16e7
changeset:   76328:c9fb9f5e16e7
parent:      76324:1a9252280f07
user:        Brett Cannon <brett at python.org>
date:        Sun Apr 15 14:15:31 2012 -0400
summary:
  Set ImportError.name when raising the exception in the case of None
found in sys.modules.

files:
  Python/import.c |  7 +++++--
  1 files changed, 5 insertions(+), 2 deletions(-)


diff --git a/Python/import.c b/Python/import.c
--- a/Python/import.c
+++ b/Python/import.c
@@ -2980,8 +2980,11 @@
 
     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) {

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list