New submission from Ronald Oussoren <ronaldousso...@mac.com>:
The documentation for import lib.machinery.ModuleSpec says that the attribute "loader" should be None for namespace packages (see <https://docs.python.org/3/library/importlib.html#importlib.machinery.ModuleSpec>) In reality the loader for namespace packages is an instance of a private class, and that class does not conform to the importlib.abc.Loader ABC. To reproduce: * Create and empty directory "namespace" * (Optionally) create an empty "module.py" in that directory * Start a python shell and follow along: Python 3.7.2 (v3.7.2:9a3ffc0492, Dec 24 2018, 02:44:43) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import namespace >>> namespace.__loader__ <_frozen_importlib_external._NamespaceLoader object at 0x104c7bdd8> >>> import importlib.abc >>> isinstance(namespace.__loader__, importlib.abc.Loader) False >>> import importlib.util >>> importlib.util.find_spec('namespace') ModuleSpec(name='namespace', loader=<_frozen_importlib_external._NamespaceLoader object at 0x104c7bdd8>, submodule_search_locations=_NamespacePath(['/Users/ronald/Projects/pyobjc-hg/modulegraph2/namespace'])) Note how "namespace" has an attribute named "__loader__" that is not None, and the same is true for the ModuleSpec found using importlib.util.find_spec. The loader does not claim to conform to any Loader ABC (but provides all methods required for conformance to the InspectLoader ABC) I'm not sure if this should be two issues: 1) Documentation doesn't match behaviour 2) The loader for namespace packages isn't registered with the relevant ABCs P.S. the latter is also true for zipimport.zipimporter. ---------- components: Library (Lib) messages: 333111 nosy: brett.cannon, ronaldoussoren priority: normal severity: normal status: open title: Loader for namespace packages type: behavior versions: Python 3.6, Python 3.7, Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue35673> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com