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

Brett Cannon brett at python.org
Tue Apr 24 01:23:22 CEST 2007


On 4/23/07, Phillip J. Eby <pje at telecommunity.com> wrote:
> At 03:16 PM 4/23/2007 -0700, Brett Cannon wrote:
> >The PEP does not explicitly state how to signal that a loader cannot
> >load a module it is asked to.  This could happen if someone called a
> >loader without consulting its respective importer.  I would want to
> >add something like:
> >"""
> >If the loader is unable to load the specified module and a specific
> >exception is not raised in determining this, ImportError is raised.
> >This may occur if a loader is called without first consulting an
> >importer as to if the loader can load the specified module but the
> >loader is aware of the fact it cannot fulfill the request made.
> >"""
>
> Okay, now I understand what you're trying to say, but I still don't
> understand what the purpose is.  I mean, what else would you do except
> raise an error?  I.e., isn't the actual contract "load the specified module
> or raise an exception of some kind"?

Not if you read the PEP.  It doesn't explicitly say what should happen.

I want to standardize on raising ImportError.  The PEP itself has two
ways of signaling an error; find_module() returns None instead of
raising an error to signal it can't do something while path hooks
raise ImportError.  I just want to be as explicit as possible.

-Brett


More information about the Python-Dev mailing list