classification
Title: pkgutil.get_loader is broken
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, Pavel.Aslanov, brett.cannon, eric.araujo, ncoghlan
Priority: normal Keywords: patch

Created on 2012-05-03 10:45 by Pavel.Aslanov, last changed 2012-05-04 16:38 by eric.araujo.

Files
File name Uploaded Description Edit
python_pkgutil_bug.patch Pavel.Aslanov, 2012-05-03 10:45
Messages (4)
msg159848 - (view) Author: Pavel Aslanov (Pavel.Aslanov) Date: 2012-05-03 10:45
if module was marked as not existing by setting sys.modules [fullname] to None, then pkgutil.get_loader (fullname) will throw AttributeError.

Example:
#! /usr/bin/evn python
import unittest
import pkgutil

def main ():
    pkgutil.get_loader ('unittest.functools')

if __name__ == '__main__':
    main ()

Patch is attached
msg159861 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2012-05-03 15:19
So I'm no pkgutil expert, but at least in the case of None in sys.modules, that triggers at least an ImportError in __import__ if that is come across.
msg159900 - (view) Author: Pavel Aslanov (Pavel.Aslanov) Date: 2012-05-04 04:17
Main use case of pkgutil.get_loader is to determine if its possible to load module and either return loader or None. But it throws exception more over it is AttributeErrror exception.
msg159901 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2012-05-04 04:36
I'm not yet sure the proposed fix in the patch is the right approach (I need to look at the surrounding code), but I believe Pavel's right that get_loader() should be returning None in this case instead of throwing an exception.
History
Date User Action Args
2012-05-04 16:38:04eric.araujosetnosy: + eric.araujo
2012-05-04 04:41:48Arfreversetnosy: + Arfrever
2012-05-04 04:36:28ncoghlansetmessages: + msg159901
2012-05-04 04:17:18Pavel.Aslanovsetmessages: + msg159900
2012-05-03 15:19:27brett.cannonsetmessages: + msg159861
2012-05-03 10:54:44pitrousetnosy: + brett.cannon, ncoghlan
2012-05-03 10:45:40Pavel.Aslanovcreate