This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: pkgutil.ImpImporter(None).iter_modules() does not search sys.path
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.3
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, chris.jerdonek, eric.araujo, ncoghlan
Priority: normal Keywords: easy, patch

Created on 2012-07-08 21:48 by chris.jerdonek, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue-15299-failing-test.patch chris.jerdonek, 2012-07-09 14:10 review
Messages (5)
msg165038 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2012-07-08 21:48
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).
msg165082 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2012-07-09 13:18
I'm working on a test for this.
msg165083 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2012-07-09 14:10
Add failing tests.
msg165455 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2012-07-14 15:57
In addition, before changing ImpImporter.iter_modules(), we should probably also add some tests of the method for values of self.path that do work (i.e. for when self.path is not None).  The method is currently untested.

I can work on adding tests for that over the next few days.
msg165498 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2012-07-15 03:43
The pkgutil import emulation is being deprecated in 3.3

However, I'll use this as useful input for any new walk_packages tests added while resolving #15343
History
Date User Action Args
2022-04-11 14:57:32adminsetgithub: 59504
2012-07-15 03:43:05ncoghlansetstatus: open -> closed
resolution: wont fix
messages: + msg165498

stage: needs patch -> resolved
2012-07-14 16:38:26brett.cannonsetnosy: - brett.cannon
2012-07-14 15:57:01chris.jerdoneksetkeywords: + easy

messages: + msg165455
2012-07-14 12:59:49eric.araujosetnosy: + brett.cannon, ncoghlan, eric.araujo
2012-07-09 14:10:17chris.jerdoneksetfiles: + issue-15299-failing-test.patch
keywords: + patch
messages: + msg165083

stage: test needed -> needs patch
2012-07-09 13:18:34chris.jerdoneksetmessages: + msg165082
stage: test needed
2012-07-09 13:17:09Arfreversetnosy: + Arfrever
2012-07-08 21:49:04chris.jerdoneksettitle: ImpImporter(None).iter_modules() does not search sys.path -> pkgutil.ImpImporter(None).iter_modules() does not search sys.path
2012-07-08 21:48:06chris.jerdonekcreate