From: Victor Stinner Date: Thu, 15 Sep 2011 17:28:05 +0000 (+0200) Subject: Fix the import machinery if there is an error on sys.path or sys.meta_path X-Git-Tag: v3.3.0a1~1531^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1619132e5dba825cdfae200cf619470129116c3d;p=python 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. --- diff --git a/Python/import.c b/Python/import.c index 93defeff7f..ee905eb286 100644 --- a/Python/import.c +++ b/Python/import.c @@ -1591,7 +1591,7 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf, meta_path = PySys_GetObject("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 " "import hooks"); return NULL; @@ -1641,14 +1641,14 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf, } if (path == NULL || !PyList_Check(path)) { - PyErr_SetString(PyExc_ImportError, + PyErr_SetString(PyExc_RuntimeError, "sys.path must be a list of directory names"); return NULL; } path_hooks = PySys_GetObject("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 " "import hooks"); return NULL; @@ -1656,7 +1656,7 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf, path_importer_cache = PySys_GetObject("path_importer_cache"); if (path_importer_cache == NULL || !PyDict_Check(path_importer_cache)) { - PyErr_SetString(PyExc_ImportError, + PyErr_SetString(PyExc_RuntimeError, "sys.path_importer_cache must be a dict"); return NULL; }