[issue2439] Patch to add a get_data function to pkgutil

Paul Moore report at bugs.python.org
Fri Mar 21 00:55:33 CET 2008


Paul Moore <p.f.moore at gmail.com> added the comment:

Is that true? loader.load_module(pkg) should return sys.modules[pkg]
without reloading if it already exists. See PEP 302 "Specification part
1: The Importer Protocol":

The load_module() method has a few responsibilities that it must
fulfil *before* it runs any code:

 - If there is an existing module object named 'fullname' in
   sys.modules, the loader must use that existing module.
   (Otherwise, the reload() builtin will not work correctly.)
   If a module named 'fullname' does not exist in sys.modules,
   the loader must create a new module object and add it to
   sys.modules.

I've added a test for this, but I'm not 100% sure it's right. It
certainly works with unchanged code. If you can make it fail, let me
know and I'll work up a fix. But I think repeated calls to load_module()
should be safe (assuming loaders work as required by PEP 302).

Added file: http://bugs.python.org/file9799/pkgutil.patch

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2439>
__________________________________


More information about the Python-bugs-list mailing list