Bug report
For the following tree, where ./b is not a package, PathFinder.find_spec("a.b") raises an undocumented KeyError:
.
├── a
│ ├── b.py
└── b
>>> from importlib.machinery import PathFinder >>> PathFinder.find_spec("a.b") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<frozen importlib._bootstrap_external>", line 1439, in find_spec File "<frozen importlib._bootstrap_external>", line 1218, in __init__ File "<frozen importlib._bootstrap_external>", line 1233, in _get_parent_path KeyError: 'a'
Works as expected if a is provided as the path argument:
>>> PathFinder.find_spec("a.b", path=["a"]) ModuleSpec(name='a.b', loader=<_frozen_importlib_external.SourceFileLoader object at 0x100d37d30>, origin='/Users/myuser/a/b.py')
Your environment
Python 3.10.2 (v3.10.2:a58ebcc701, Jan 13 2022, 14:50:16) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Also reproduced on 3.8 and 3.12.0a0