[Python-Dev] PEP 302 and 'reload()'
Phillip J. Eby
pje at telecommunity.com
Thu Sep 16 23:14:07 CEST 2004
At 05:38 PM 9/8/04 -0400, Phillip J. Eby wrote:
>It appears to me there is an error in both PEP 302's specification and its
>implementation concerning the correct operation of reload(). First, it says:
>
> The load_module() method has a few responsibilities that it must
> fulfill *before* it runs any code:
>
> - It must create the module object. From Python this can be done
> via the new.module() function, the imp.new_module() function or
> via the module type object; from C with the PyModule_New()
> function or the PyImport_ModuleAdd() function.
>
>This should probably say that if the module already exists in sys.modules,
>it should reuse the existing module object, rather than creating a new
>one. Otherwise, 'reload()' cannot fulfill its contract.
>
>Second, the actual implementation of PyImport_ReloadModule doesn't
>actually use a loader object, so reload() doesn't work with import hooks
>at all. There's an SF bug report for this, and a patch to fix it (that
>also adds a test to test_importhooks to ensure that 'reload()' actually
>invokes the loader.
>
>Are there any objections to me fixing either/both of these, and
>backporting the bugfix to the 2.3 maintenance branch?
Since there have been no objections, I'll undertake (schedule permitting)
to correct PEP 302, fix PyImport_ReloadModule
and Lib/test/test_importhooks, and backport the changes.
I'll note that there are other issues that affect reloading from e.g.
zipfiles, but those are over my head to tackle at present. However, until
the PEP 302-level issues are dealt with, there's no chance of fixing
reload-from-zip, since the underlying reload mechanism itself is broken
with respect to PEP 302.
>Also, should PyImport_ReloadModule use the import lock? It doesn't
>currently, but I'm not clear on why it doesn't.
Since noone has answered this, I'll have to assume that there is a good
reason, and won't fiddle with it. But I'd still appreciate an answer.
More information about the Python-Dev
mailing list