New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pkgutil.iter_zipimport_modules ignores the prefix parameter for packages #58417
Comments
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/ 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:
to
Thanks, James P.s, This is my first Python bug report. I apologise in advance for any poor etiquette. |
Adding Brett, since the plan is to clear out a lot of the redundant code in pkgutil once importlib is fully bootstrapped as the standard import implementation. (although this will still affect the older versions directly) |
Brett, Facebook is using the proposed patch in prod since last year. It works fine. Maybe we should just include it for the time being? |
I don't deal with pkgutil so I have no problem if you want to go ahead and apply the patch if you think it's reasonable to accept, Łukasz. |
+1 for just including the fix in the next round of maintenance releases, although a test case would be desirable. |
New changeset 9649acf7d472 by Łukasz Langa in branch '3.5': New changeset 389b7456a053 by Łukasz Langa in branch 'default': |
Done. Fix is going to be present for 3.5.2 and 3.6. Thank you, James. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: