Skip to content

Commit 1619132

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 7974642 commit 1619132

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
@@ -1591,7 +1591,7 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf,
15911591

15921592
meta_path = PySys_GetObject("meta_path");
15931593
if (meta_path == NULL || !PyList_Check(meta_path)) {
1594-
PyErr_SetString(PyExc_ImportError,
1594+
PyErr_SetString(PyExc_RuntimeError,
15951595
"sys.meta_path must be a list of "
15961596
"import hooks");
15971597
return NULL;
@@ -1641,22 +1641,22 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf,
16411641
}
16421642

16431643
if (path == NULL || !PyList_Check(path)) {
1644-
PyErr_SetString(PyExc_ImportError,
1644+
PyErr_SetString(PyExc_RuntimeError,
16451645
"sys.path must be a list of directory names");
16461646
return NULL;
16471647
}
16481648

16491649
path_hooks = PySys_GetObject("path_hooks");
16501650
if (path_hooks == NULL || !PyList_Check(path_hooks)) {
1651-
PyErr_SetString(PyExc_ImportError,
1651+
PyErr_SetString(PyExc_RuntimeError,
16521652
"sys.path_hooks must be a list of "
16531653
"import hooks");
16541654
return NULL;
16551655
}
16561656
path_importer_cache = PySys_GetObject("path_importer_cache");
16571657
if (path_importer_cache == NULL ||
16581658
!PyDict_Check(path_importer_cache)) {
1659-
PyErr_SetString(PyExc_ImportError,
1659+
PyErr_SetString(PyExc_RuntimeError,
16601660
"sys.path_importer_cache must be a dict");
16611661
return NULL;
16621662
}

0 commit comments

Comments
 (0)