Skip to content
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

PathFinder.find_spec() can raise bare KeyError when path=None #93334

Open
jacobtylerwalls opened this issue May 29, 2022 · 1 comment
Open

PathFinder.find_spec() can raise bare KeyError when path=None #93334

jacobtylerwalls opened this issue May 29, 2022 · 1 comment
Labels
3.10 3.11 3.12 expert-importlib type-bug

Comments

@jacobtylerwalls
Copy link
Contributor

@jacobtylerwalls jacobtylerwalls commented May 29, 2022

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

@jacobtylerwalls
Copy link
Contributor Author

@jacobtylerwalls jacobtylerwalls commented May 30, 2022

I see from #89754 that this is invalid/poor usage, but probably None is the better outcome?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.10 3.11 3.12 expert-importlib type-bug
Projects
None yet
Development

No branches or pull requests

2 participants