comparison Python/import.c @ 72386:3ff9a2d5f5e5

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.
author Victor Stinner <victor.stinner@haypocalc.com>
date Thu, 15 Sep 2011 19:38:54 +0200
parents aaab27d4c99c 4247f5e221c6
children 03843a8d3244
comparison
equal deleted inserted replaced
72384:c6d52971dd2a 72386:3ff9a2d5f5e5
1990 if (p_loader != NULL) { 1990 if (p_loader != NULL) {
1991 PyObject *meta_path; 1991 PyObject *meta_path;
1992 1992
1993 meta_path = PySys_GetObject("meta_path"); 1993 meta_path = PySys_GetObject("meta_path");
1994 if (meta_path == NULL || !PyList_Check(meta_path)) { 1994 if (meta_path == NULL || !PyList_Check(meta_path)) {
1995 PyErr_SetString(PyExc_ImportError, 1995 PyErr_SetString(PyExc_RuntimeError,
1996 "sys.meta_path must be a list of " 1996 "sys.meta_path must be a list of "
1997 "import hooks"); 1997 "import hooks");
1998 return NULL; 1998 return NULL;
1999 } 1999 }
2000 Py_INCREF(meta_path); /* zap guard */ 2000 Py_INCREF(meta_path); /* zap guard */
2042 #endif 2042 #endif
2043 search_path_list = PySys_GetObject("path"); 2043 search_path_list = PySys_GetObject("path");
2044 } 2044 }
2045 2045
2046 if (search_path_list == NULL || !PyList_Check(search_path_list)) { 2046 if (search_path_list == NULL || !PyList_Check(search_path_list)) {
2047 PyErr_SetString(PyExc_ImportError, 2047 PyErr_SetString(PyExc_RuntimeError,
2048 "sys.path must be a list of directory names"); 2048 "sys.path must be a list of directory names");
2049 return NULL; 2049 return NULL;
2050 } 2050 }
2051 2051
2052 path_hooks = PySys_GetObject("path_hooks"); 2052 path_hooks = PySys_GetObject("path_hooks");
2053 if (path_hooks == NULL || !PyList_Check(path_hooks)) { 2053 if (path_hooks == NULL || !PyList_Check(path_hooks)) {
2054 PyErr_SetString(PyExc_ImportError, 2054 PyErr_SetString(PyExc_RuntimeError,
2055 "sys.path_hooks must be a list of " 2055 "sys.path_hooks must be a list of "
2056 "import hooks"); 2056 "import hooks");
2057 return NULL; 2057 return NULL;
2058 } 2058 }
2059 path_importer_cache = PySys_GetObject("path_importer_cache"); 2059 path_importer_cache = PySys_GetObject("path_importer_cache");
2060 if (path_importer_cache == NULL || 2060 if (path_importer_cache == NULL ||
2061 !PyDict_Check(path_importer_cache)) { 2061 !PyDict_Check(path_importer_cache)) {
2062 PyErr_SetString(PyExc_ImportError, 2062 PyErr_SetString(PyExc_RuntimeError,
2063 "sys.path_importer_cache must be a dict"); 2063 "sys.path_importer_cache must be a dict");
2064 return NULL; 2064 return NULL;
2065 } 2065 }
2066 2066
2067 return find_module_path_list(fullname, name, 2067 return find_module_path_list(fullname, name,