Author dgreiman
Recipients dgreiman
Date 2008-02-17.23:11:16
SpamBayes Score 0.00103341
Marked as misclassified No
Message-id <>
This patch reorganizes import.c to move functionality into two new PEP
302-style Importer objects.  I attempted to change as little as
feasible, but the patch is still ~4700 lines long, about 1000 of which
is new tests.

BuiltinImporter: handles C_BUILTIN and PY_FROZEN modules
DirectoryImporter: handles PY_SOURCE, PY_COMPILED, PKG_DIRECTORY,

BuiltinImporter is put on sys.meta_path, DirectoryImporter is put on

To preserve backward compatibility of methods like imp.find_module(),
they use new variables sys.builtin_meta_path and sys.builtin_path_hooks
which are analogous to sys.meta_path and sys.path_hook but contain only
the two importer objects above.

Character encoding issues were substantial.  The existing code was
somewhat inscrutable in this regard.  The tests disabled in issue 1377
were re-added with more safeguards and harder tests.  It is possible to
import modules with non-ascii names from non-ascii paths.  Tested on
Windows XP and Linux.

Areas for discussion:

Naming: Names of the importer classes, names of variables, etc

sys: I added three variables to sys.  Is there a better alternative?

ModuleInfo: The importers use a somewhat tricky way to store an open
file between calls to importer.find_module() and importer.load_module(),
so that the new code doesn't do any more system calls that the old code.

semantics: There are many import corner cases where the semantics are
unknown or unclear.  

Frozen packages: the __path__ of a frozen package is a string rather
than a list, and it is possible to replace that string to change how
imports inside that package are resolved.  I have attempted to keep that
functionality intact but it's not clear that it's a feature rather than
a bug.
Date User Action Args
2008-02-17 23:11:19dgreimansetspambayes_score: 0.00103341 -> 0.00103341
recipients: + dgreiman
2008-02-17 23:11:19dgreimansetspambayes_score: 0.00103341 -> 0.00103341
messageid: <>
2008-02-17 23:11:18dgreimanlinkissue2135 messages
2008-02-17 23:11:17dgreimancreate