[Distutils] [setuptools] Bug in setuptools ImpLoader

Jeremy Kloth jeremy.kloth at 4suite.org
Fri Sep 8 22:04:00 CEST 2006

On Friday 08 September 2006 1:16 pm, Phillip J. Eby wrote:
> At 12:24 PM 9/8/2006 -0600, Jeremy Kloth wrote:
> > >From PEP 302:
> >
> >   The load_module() method has a few responsibilities that it must
> >     fulfill *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.
> >(emphasis on must)
> >
> >The current implementation always reloads the module if it exists.
> Yes, that's the *intent* of the above paragraph.  An importer that
> *doesn't* reload under these circumstances will break the reload() builtin.

I read the paragraph as stating that the loader *returns* the module from 
sys.modules instantly or it would break reload().  After re-reading PEP 302 
several times, it becomes clear that the intention is that the module's 
contents are replaced before returning the module.

> >   This
> >problem exists in both the 0.6 and 0.7 series.  Since pkgutil is in Python
> >2.5, this is an issue there as well.
> Unless I've misunderstood you, this is not a problem, it's the correct and
> intended behavior.  When a loader is asked to load a module that's in
> sys.modules, it's supposed to *reload* it.  Otherwise, the reload() builtin
> won't work.

It would be worth adding a sentence stating that loader.load_module() is the 
same as a reload() if the module is already imported (just like the docs for 

My confusion, no problem here except for in the code that was expecting my 
concept for things to work.

Jeremy Kloth

More information about the Distutils-SIG mailing list