diff options
| author | Brett Cannon <brett@python.org> | 2012-04-15 14:15:31 -0400 |
|---|---|---|
| committer | Brett Cannon <brett@python.org> | 2012-04-15 14:15:31 -0400 |
| commit | 1d6e335a95def2f9b4c7855ad0cd84c0c387ae45 (patch) | |
| tree | 79148fc2c3a59ca3e97ecf68f24669acce7180a9 /Python/import.c | |
| parent | 36f460c15c57abc3b518205be54b8bbc6ef315bc (diff) | |
| download | cpython-1d6e335a95def2f9b4c7855ad0cd84c0c387ae45.tar.gz | |
Set ImportError.name when raising the exception in the case of None
found in sys.modules.
Diffstat (limited to 'Python/import.c')
| -rw-r--r-- | Python/import.c | 7 |
1 files changed, 5 insertions, 2 deletions
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) { |
