[Python-Dev] Clarifications for import PEPs (302 and 328) (original) (raw)
Phillip J. Eby pje at telecommunity.com
Tue Apr 24 03:21:46 CEST 2007
- Previous message: [Python-Dev] Clarifications for import PEPs (302 and 328)
- Next message: [Python-Dev] Clarifications for import PEPs (302 and 328)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
At 04:23 PM 4/23/2007 -0700, Brett Cannon wrote:
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; findmodule() 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.
Ok, so this should at least lose the passive voice ("ImportError is raised") -- it should say that it's the loader's job to raise ImportError. Otherwise, it's not actually removing any ambiguity.
I also don't find the "This may occur" sentence to be helpful; it seems we should just say, "load_module() must return a loaded module or raise an error, preferably an ImportError unless an existing exception is being propagated."
Meanwhile, if you also mean to say that load_module() is explicitly allowed to fail with an ImportError when it's asked for any module other than the one it was obtained for (via find_module()), then let's say that, too.
Notice, by the way, that this is a stronger condition than the one you proposed, yet it doesn't imply that there is or should be an ongoing relationship between the loader and the importer. It also doesn't imply that perhaps it's okay for a loader to not succeed in reloading the same module! (i.e., as I understand it, a module can currently invoke loader.load_module(name) as a rough synonym for reload().)
- Previous message: [Python-Dev] Clarifications for import PEPs (302 and 328)
- Next message: [Python-Dev] Clarifications for import PEPs (302 and 328)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]