[Python-Dev] How to interpret get_code from PEP 302?

Brett Cannon brett at python.org
Tue Aug 21 05:57:17 CEST 2007


PEP 302 ("New Import Hooks") has an optional extensions section so
that tools like py2exe and py2app have an easier time.  Part of the
optional extensions is the method get_code that is to return the code
object for the specified method (if the loader can handle it).

But there is a lack in the definition of how get_code is supposed to
be implemented.  The definition says that the "method should return
the code object associated with the module", which is fine.  But then
it goes on to state that "If the loader doesn't have the code object
but it _does_ have the source code, it should return the compiled
source code".  This throws me as this makes it sound like bytecode
does not need to be used if the loader does not already have a code
object and there is no source to be had; any bytecode can be ignored.

Now I doubt this is how it is supposed to be read.  Does anyone
disagree with that?  If not, I will change the wording to mention that
bytecode must be used if no source is available (and that the magic
number must be verified).

-Brett


More information about the Python-Dev mailing list