[Import-SIG] Rough PEP: A ModuleSpec Type for the Import System

Nick Coghlan ncoghlan at gmail.com
Sat Aug 10 12:50:25 CEST 2013


On 10 August 2013 08:44, Eric Snow <ericsnowcurrently at gmail.com> wrote:
> On Fri, Aug 9, 2013 at 1:22 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
>>
>> Well, is there another way to use load() than:
>> - load(): load a new module
>> - load(existing_module, is_reload=True): reload an existing module
>>
>> I mean, does it make sense to call e.g.
>> - load(some_existing_module, is_reload=False)
>
>
> This would be a ValueError.  The module argument is meant just for reload.
> I'm not sure it makes sense otherwise.  Perhaps so you could prepare your
> own new module prior to calling load()?  I'd like to leave that off the
> table for this PEP.

The advantage of offering that API over telling people to call
spec.load.exec_module(m) directly is that it gives us more control
over the loading process (by updating ModuleSpec.load), avoiding the
current problem we have where providing new load time behaviour is
difficult because we don't control the loader implementations.

>>
>> - load(is_reload=True)
>
>
> This was always okay in my mind, but I realized it did not make it to the
> PEP until Brett had some similar questions. :)  The updated PEP covers this.
> Like I told Brett, I'm going to see how a separate reload() looks and go
> from there.

A separate reload that works something like this sounds good to me:

    def reload(self, module=None):
        if module is None:
            module = sys.modules[self.name]
        self.load(module)

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Import-SIG mailing list