[Python-Dev] PEP 451 update (original) (raw)

Nick Coghlan ncoghlan at gmail.com
Thu Oct 31 05:24:17 CET 2013


On 31 Oct 2013 08:54, "Eric Snow" <ericsnowcurrently at gmail.com> wrote:

On Wed, Oct 30, 2013 at 4:09 PM, Nick Coghlan <ncoghlan at gmail.com> wrote: > On 31 Oct 2013 03:41, "Eric Snow" <ericsnowcurrently at gmail.com> wrote: >> Our recent discovery about reloading should probably be reflected in >> the signature of finder.findspec(): >> >> MetaPathFinder.findspec(name, path=None, existing=None) >> PathEntryFinder.findspec(name, existing=None) >> >> This way the finder has an opportunity to incorporate information from >> an existing spec into the spec it returns. reload() would make use of >> this by passing module.spec (or None if the module has no >> spec) to bootstrap.findspec(). >> >> This approach should also address what you are looking for. I'd >> prefer it over passing the existing spec to execmodule(). The module >> (and its spec) should have everything execmodule() needs to do >> its job. > > Yes, that should work. Cool. I'll update the PEP. > >> We would still need to use loader.supportsreload() in reload(). > > Why? If the reload isn't supported, execmodule can just throw an exception > based on the loader state in the spec. At the point that execmodule() gets called, the loader can't check sys.modules to see if it's a reload or not. As a workaround, the finder could set up some loader state to indicate to the loader that it's a reload and then the loader, during execmodule(), would check that and act accordingly. However, that's the sort of boilerplate that PEP 451 is trying to offload onto the import machinery. With Loader.supportsreload() it's a lot cleaner.

There's also the option of implementing the constraint directly in the finder, which does have the necessary info (with the change to pass the previous spec to find_spec).

I still think it makes more sense to leave this out for the moment - it's not at all clear we need the extra method, and adding it later would be a straightforward protocol update.

Cheers, Nick.

-eric > > From the import system's point of view "reload not permitted" is no > different from any other exec time failure. > > Cheers, > Nick. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20131031/747f9cbd/attachment.html>



More information about the Python-Dev mailing list