[Python-Dev] importlib.find_loader

Thomas Heller theller at ctypes.org
Thu Jan 31 21:32:39 CET 2013


In Python3.3, I thought that every loaded module has a __loader__
attribute. Apparently this is not the case for a few builtin modules:

Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 
bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> import importlib
 >>>
 >>> def bug():
...     for name in list(sys.modules.keys()):
...         try:
...             importlib.find_loader(name)
...         except Exception as details:
...             print(name, type(details), details)
...
 >>> bug()
_frozen_importlib <class 'AttributeError'> 'module' object has no 
attribute '__loader__'
builtins <class 'AttributeError'> 'module' object has no attribute 
'__loader__'
signal <class 'AttributeError'> 'module' object has no attribute 
'__loader__'
importlib._bootstrap <class 'AttributeError'> 'module' object has no 
attribute '__loader__'
 >>>


However, the importlib docs talk about a ValueError instead of the 
AttributeError that I see above:

> Find the loader for a module, optionally within the specified path.
> If  the module is in sys.modules, then sys.modules[name].__loader__
 > is returned (unless the loader would be None, in which case
 > ValueError is raised).

Is this a bug?

Thomas



More information about the Python-Dev mailing list