Skip to content

Commit ed36c06

Browse files
author
Victor Stinner
committed
Fix the import machinery if there is an error on sys.path or sys.meta_path
find_module() now raises a RuntimeError, instead of ImportError, on an error on sys.path or sys.meta_path because load_package() and import_submodule() returns None and clear the exception if a ImportError occurred.
1 parent 503e5e1 commit ed36c06

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

Python/import.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf,
12351235

12361236
meta_path = PySys_GetObject("meta_path");
12371237
if (meta_path == NULL || !PyList_Check(meta_path)) {
1238-
PyErr_SetString(PyExc_ImportError,
1238+
PyErr_SetString(PyExc_RuntimeError,
12391239
"sys.meta_path must be a list of "
12401240
"import hooks");
12411241
return NULL;
@@ -1304,22 +1304,22 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf,
13041304
path = PySys_GetObject("path");
13051305
}
13061306
if (path == NULL || !PyList_Check(path)) {
1307-
PyErr_SetString(PyExc_ImportError,
1307+
PyErr_SetString(PyExc_RuntimeError,
13081308
"sys.path must be a list of directory names");
13091309
return NULL;
13101310
}
13111311

13121312
path_hooks = PySys_GetObject("path_hooks");
13131313
if (path_hooks == NULL || !PyList_Check(path_hooks)) {
1314-
PyErr_SetString(PyExc_ImportError,
1314+
PyErr_SetString(PyExc_RuntimeError,
13151315
"sys.path_hooks must be a list of "
13161316
"import hooks");
13171317
return NULL;
13181318
}
13191319
path_importer_cache = PySys_GetObject("path_importer_cache");
13201320
if (path_importer_cache == NULL ||
13211321
!PyDict_Check(path_importer_cache)) {
1322-
PyErr_SetString(PyExc_ImportError,
1322+
PyErr_SetString(PyExc_RuntimeError,
13231323
"sys.path_importer_cache must be a dict");
13241324
return NULL;
13251325
}

0 commit comments

Comments
 (0)