[Python-Dev] Python/import.c
Thomas Heller
theller at python.net
Mon Jun 7 10:11:07 EDT 2004
In the context of http://www.python.org/sf/845802 I'm looking at the
code in Python/import.c, function load_package().
The latter part of the function is this code, which tries to import the
__init__.py file, after building the module object in 'm', and
initializing it's __file__ and __path__ attributes:
fdp = find_module(name, "__init__", path, buf, sizeof(buf), &fp, NULL);
if (fdp == NULL) {
if (PyErr_ExceptionMatches(PyExc_ImportError)) {
PyErr_Clear();
}
else
m = NULL;
goto cleanup;
}
m = load_module(name, fp, buf, fdp->type, NULL);
if (fp != NULL)
fclose(fp);
cleanup:
Py_XDECREF(path);
Py_XDECREF(file);
return m;
}
I do not understand why the function doesn't fail when find_module
returns NULL because of an PyExc_ImportError. For the above mentioned
bug, when __init__.py is a directory instead of a file, find_module
returns NULL.
Thomas
More information about the Python-Dev
mailing list