[Python-Dev] Clarifications for import PEPs (302 and 328)

Brett Cannon brett at python.org
Mon Apr 23 23:01:28 CEST 2007

After my import rewrite, I discovered some things that were left out
of both PEP 302 (import hooks) and PEP 328 (absolute/relative
imports).  I wanted to run them by everyone before I made the
subsequent changes to the PEPs.

For PEP 302, a loader should raise ImportError if load_module fails
w/o an explicit exception being raised.  Also, __name__ needs to be
set along with __file__ (if applicable as 'sys' does not define
__file__) before the execution of code proceeds.

For PEP 328, None redirection (if 'pkg.string' is set to None the
import machinery is supposed to automatically return the 'string'
module) should be removed when absolute/relative imports become the
default.  The redirection was a hack to optimize for import's old
semantics of trying a relative import first and then an absolute
import.  The new semantics do away with the fallback and thus this
mechanism is worthless.


More information about the Python-Dev mailing list