Commit 84b8e40f authored by Victor Stinner's avatar Victor Stinner

Merge 3.2: 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.
parents 37ccd6f7 1619132e
...@@ -1992,7 +1992,7 @@ find_module(PyObject *fullname, PyObject *name, PyObject *search_path_list, ...@@ -1992,7 +1992,7 @@ find_module(PyObject *fullname, PyObject *name, PyObject *search_path_list,
meta_path = PySys_GetObject("meta_path"); meta_path = PySys_GetObject("meta_path");
if (meta_path == NULL || !PyList_Check(meta_path)) { if (meta_path == NULL || !PyList_Check(meta_path)) {
PyErr_SetString(PyExc_ImportError, PyErr_SetString(PyExc_RuntimeError,
"sys.meta_path must be a list of " "sys.meta_path must be a list of "
"import hooks"); "import hooks");
return NULL; return NULL;
...@@ -2044,14 +2044,14 @@ find_module(PyObject *fullname, PyObject *name, PyObject *search_path_list, ...@@ -2044,14 +2044,14 @@ find_module(PyObject *fullname, PyObject *name, PyObject *search_path_list,
} }
if (search_path_list == NULL || !PyList_Check(search_path_list)) { if (search_path_list == NULL || !PyList_Check(search_path_list)) {
PyErr_SetString(PyExc_ImportError, PyErr_SetString(PyExc_RuntimeError,
"sys.path must be a list of directory names"); "sys.path must be a list of directory names");
return NULL; return NULL;
} }
path_hooks = PySys_GetObject("path_hooks"); path_hooks = PySys_GetObject("path_hooks");
if (path_hooks == NULL || !PyList_Check(path_hooks)) { if (path_hooks == NULL || !PyList_Check(path_hooks)) {
PyErr_SetString(PyExc_ImportError, PyErr_SetString(PyExc_RuntimeError,
"sys.path_hooks must be a list of " "sys.path_hooks must be a list of "
"import hooks"); "import hooks");
return NULL; return NULL;
...@@ -2059,7 +2059,7 @@ find_module(PyObject *fullname, PyObject *name, PyObject *search_path_list, ...@@ -2059,7 +2059,7 @@ find_module(PyObject *fullname, PyObject *name, PyObject *search_path_list,
path_importer_cache = PySys_GetObject("path_importer_cache"); path_importer_cache = PySys_GetObject("path_importer_cache");
if (path_importer_cache == NULL || if (path_importer_cache == NULL ||
!PyDict_Check(path_importer_cache)) { !PyDict_Check(path_importer_cache)) {
PyErr_SetString(PyExc_ImportError, PyErr_SetString(PyExc_RuntimeError,
"sys.path_importer_cache must be a dict"); "sys.path_importer_cache must be a dict");
return NULL; return NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment