Message165038
The pkgutil.ImpImporter documentation says that if dirname is None, ImpImporter(dirname) should create a PEP 302 importer that searches the current sys.path, plus any modules that are frozen or built-in:
http://docs.python.org/dev/library/pkgutil.html#pkgutil.ImpImporter
However, the iter_modules() method of an ImpImporter instance doesn't search sys.path if dirname is None. It returns a generator that always yields nothing. For example--
Python 3.3.0b1 (default:5d43154d68a8, Jul 8 2012, 13:54:45)
[GCC 4.2.1 Compatible Apple Clang 3.1 (tags/Apple/clang-318.0.58)] on darwin
>>> from pkgutil import ImpImporter
>>> importer = ImpImporter()
>>> list(importer.iter_modules())
[]
Strictly speaking, one could say the documentation only applies to the find_module() method since that's the only method covered by the PEP 302 API However, iter_modules() is a public method. So I think that either iter_modules() should be fixed, made private, or else the documentation clarified by saying that searching sys.path does not apply to iter_modules().
I'm pretty sure though that iter_modules() should be fixed. This is because there are other functions in pkgutil that seem not to work because ImpImporter.iter_modules() behaves the way it does (specifically calling pkgutil.iter_modules() with path=None). |
|
Date |
User |
Action |
Args |
2012-07-08 21:48:07 | chris.jerdonek | set | recipients:
+ chris.jerdonek |
2012-07-08 21:48:07 | chris.jerdonek | set | messageid: <1341784087.15.0.754005593473.issue15299@psf.upfronthosting.co.za> |
2012-07-08 21:48:06 | chris.jerdonek | link | issue15299 messages |
2012-07-08 21:48:05 | chris.jerdonek | create | |
|