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.

Author martin.panter
Recipients Arfrever, Pathangi Jatinshravan, brett.cannon, eric.snow, martin.panter, ncoghlan, r.david.murray
Date 2015-10-14.05:59:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1444802342.28.0.583121347024.issue25372@psf.upfronthosting.co.za>
In-reply-to
Content
My use case is for Readline auto-completion, to list submodules of a package given by the user, without importing anything unnecessary. The original code is compatible with Python 2, but I am also writing a patch for 3.6 that wouldn't need that. The original implementation is like this pseudocode:

def list_submodules(package):
    # Ensure it is a package before loading or importing it
    for name in parent_packages:
        loader = pkgutil.find_loader(name)
        assert loader.is_package()
    # Could call importlib.import_module(), but this seemed easier because I already have the loader:
    package = loader.load_module(name)
    # The only reason I want to load the module:
    search_path = package.__path__
    return pkgutil.iter_modules(search_path)

Thanks for your feedback Brett. I have changed over to importlib.import_module(), and will accept that this is just a quirk of the low level import stuff.
History
Date User Action Args
2015-10-14 05:59:02martin.pantersetrecipients: + martin.panter, brett.cannon, ncoghlan, Arfrever, r.david.murray, eric.snow, Pathangi Jatinshravan
2015-10-14 05:59:02martin.pantersetmessageid: <1444802342.28.0.583121347024.issue25372@psf.upfronthosting.co.za>
2015-10-14 05:59:02martin.panterlinkissue25372 messages
2015-10-14 05:59:01martin.pantercreate