-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
Have importlib.reload() raise ModuleNotFoundError when a spec can't be found #74037
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
importlib.reload doesn't work; gives an error about NoneType having no name attribute. See attached a simple repo testcase When run it yields the following [disappointing] result. I'm running Python3.0.6.1 (installed from brew) on OSX 10.12.3
|
First, I don't know what version you're testing against because 3.0.6.1 isn't an actual release of Python and 3.6.1 isn't released yet (unless you know something I don't know :) ). Second, the issue is that you're trying to import a module under a name which doesn't match the file specified. That's causing reload() to not be able to find the original source file to reload against, leading to the None being returned by importlib._bootstrap._find_spec() which is leading to the error you're seeing. (Remember, reload() basically runs like an import statement for the module you're reloading but recycles the module object.) Third, while an exception is reasonable in this case, it is misleading and reload() should be updated to raise an ImportError if _bootstrap._find_spec() returns None. I'm marking this issue as an easy fix since you just need to add an |
Wouldn't ModuleNotFoundError be more appropriate? |
That's a good point, Serhiy, since that's what the exception is signaling. So yes, the exception should be ModuleNotFounderror. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: