Re: Rough PEP: A ModuleSpec Type for the Import System

Nick Coghlan <[email protected]>
Newsgroups gmane.comp.python.import
Message-ID <CADiSq7cpggGfy7shUjwMnB_hk1jRedhjSdQqt6r2--_5ZCS38g@mail.gmail.com>
On 10 August 2013 08:44, Eric Snow <[email protected]> wrote:
> On Fri, Aug 9, 2013 at 1:22 PM, Antoine Pitrou <[email protected]> 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   |   [email protected]   |   Brisbane, Australia
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.