[New-bugs-announce] [issue14209] pkgutil.iter_zipimport_modules ignores the prefix parameter for packages

James Pickering report at bugs.python.org
Tue Mar 6 16:02:24 CET 2012


New submission from James Pickering <jamespic84 at googlemail.com>:

If you run pkgutil.iter_zipimport_modules with a prefix parameter, and the module in question is a package, then the prefix parameter is ignored.

The most visible symptom of this is when running pkgutil.walk_packages for a zipfile. Imagine we have a module structure like this (or create one):

a/
a/__init__.py
a/b/
a/b/__init.__py

If we put this structure in a directory, add the directory to sys.path, and run pkgutil.walk_packages(), it will find modules "a" and "a.b".

If we put this structure in a zipfile, however, we add this file to sys.path, and run pkgutil.walk_packages(), it will find modules "a" and "b". This is because pkgutil.iter_zipimport_modules ignores the prefix parameter "a.".

This is incorrect.

This can be fixed by changing line ~344 of Lib/pkgutil.py from:

    yield fn[0], True

to

    yield prefix + fn[0], True

Thanks, James

P.s, This is my first Python bug report. I apologise in advance for any poor etiquette.

----------
components: Library (Lib)
messages: 155018
nosy: James.Pickering
priority: normal
severity: normal
status: open
title: pkgutil.iter_zipimport_modules ignores the prefix parameter for packages
type: behavior
versions: Python 2.7, Python 3.2, Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14209>
_______________________________________


More information about the New-bugs-announce mailing list