[Python-Dev] importlib.find_loader

Thomas Heller theller at ctypes.org
Fri Feb 1 07:56:46 CET 2013


Am 01.02.2013 01:42, schrieb Nick Coghlan:
> Yep, looks like a bug in the bootstrapping, failing to set __loader__
> properly.

It also has the effect that reload does not work:

Type "help", "copyright", "credits" or "license" for more information.
 >>> import imp
 >>> import math
 >>> imp.reload(math)
<module 'math' (built-in)>
 >>> import signal
 >>> imp.reload(signal)
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "C:\Python33-64\lib\imp.py", line 252, in reload
     return module.__loader__.load_module(name)
AttributeError: 'module' object has no attribute '__loader__'
 >>>

> However, I also think the current handling of the "no __loader__
> attribute" case is a separate bug - since we generally aim to tolerate
> non-modules in sys.modules (albeit somewhat grudgingly), importlib
> should probably be using "getattr(mod, '__loader__', None)" rather than
> assuming the attribute will always be present.

Thomas




More information about the Python-Dev mailing list