Index: Python/import.c =================================================================== --- Python/import.c (Revision 46240) +++ Python/import.c (Arbeitskopie) @@ -1240,7 +1240,33 @@ if (importer == NULL) return NULL; /* Note: importer is a borrowed reference */ - if (importer != Py_None) { + if (importer == Py_False) { + /* Cached as not being a valid dir. */ + Py_XDECREF(copy); + continue; + } + else if (importer == Py_True) { + /* Cached as being a valid dir, so just + * continue below. */ + } + else if (importer == Py_None) { + /* No importer was found, so it has to be a file. + * Check if the directory is valid. */ +#ifdef HAVE_STAT + if (stat(buf, &statbuf) != 0) { + /* Directory does not exist. */ + PyDict_SetItem(path_importer_cache, + v, Py_False); + Py_XDECREF(copy); + continue; + } else { + PyDict_SetItem(path_importer_cache, + v, Py_True); + } +#endif + } + else { + /* A real import hook importer was found. */ PyObject *loader; loader = PyObject_CallMethod(importer, "find_module", @@ -1253,9 +1279,11 @@ return &importhookdescr; } Py_DECREF(loader); + Py_XDECREF(copy); + continue; } - /* no hook was successful, use builtin import */ } + /* no hook was found, use builtin import */ if (len > 0 && buf[len-1] != SEP #ifdef ALTSEP