-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
PathFinder.find_spec()
can raise bare KeyError
when path=None
#93334
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
Comments
I see from #89754 that this is invalid/poor usage if you know in advance that there's a resource under ModuleSpec(name='b', loader=None, submodule_search_locations=_NamespacePath(['<CWD>/b'])) |
I do not think that #98100 is the right solution. It gets rid of KeyError, but returns a wrong result. |
Thanks for taking a look @serhiy-storchaka. The result I get with #98100 is the result when the (I don't think we want to return the path to |
I think that it should be the same as if the |
I agree if Serhiy means it should raise |
Without the name collision, trying to find the submodule without a parent import or a
>>> from importlib.machinery import PathFinder
>>> PathFinder.find_spec("a.b") is None
>>> True |
Bug report
For the following tree, where
./b
is not a package,PathFinder.find_spec("a.b")
raises an undocumentedKeyError
:Works as expected if
a
is provided as thepath
argument: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
Linked PRs
The text was updated successfully, but these errors were encountered: