Skip to content

Commit 27fc528

Browse files
committed
Set ImportError.name when raising the exception in the case of None
found in sys.modules.
1 parent da4210f commit 27fc528

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Python/import.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2980,8 +2980,11 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *given_globals,
29802980

29812981
mod = PyDict_GetItem(interp->modules, abs_name);
29822982
if (mod == Py_None) {
2983-
PyErr_Format(PyExc_ImportError,
2984-
"import of %R halted; None in sys.modules", abs_name);
2983+
PyObject *msg = PyUnicode_FromFormat("import of %R halted; "
2984+
"None in sys.modules", abs_name);
2985+
if (msg != NULL) {
2986+
PyErr_SetFromImportErrorWithName(msg, abs_name);
2987+
}
29852988
goto error_with_unlock;
29862989
}
29872990
else if (mod != NULL) {

0 commit comments

Comments
 (0)