Brett Cannon added the comment: Here is why Python does when importing a module that lacks __path__:
>>> import importlib >>> del importlib.__path__ >>> import importlib.util Traceback (most recent call last): File "<stdin>", line 1, in <module> ModuleNotFoundError: No module named 'importlib.util'; 'importlib' is not a package So yes, we should change find_spec() to raise ModuleNotFoundError to match (although only in Python 3.7 since this is a breaking change). ---------- resolution: not a bug -> stage: resolved -> status: closed -> open title: importlib.find_spec raises AttributeError/ModuleNotFoundError when parent is not a package/module -> importlib.find_spec raises AttributeError when parent is not a package/module versions: +Python 3.7 -Python 3.6 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue30436> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com