Issue #15767: Touch up ModuleNotFoundError usage by import.

Forgot to raise ModuleNotFoundError when None is found in sys.modules.
This led to introducing the C function PyErr_SetImportErrorSubclass()
to make setting ModuleNotFoundError easier.

Also updated the reference docs to mention ModuleNotFoundError
appropriately. Updated the docs for ModuleNotFoundError to mention the
None in sys.modules case.

Lastly, it was noticed that PyErr_SetImportError() was not setting an
exception when returning None in one case. That issue is now fixed.
This commit is contained in:
Brett Cannon 2013-06-12 23:29:18 -04:00
parent 3e9a9ae09d
commit 8f5ac5106e
10 changed files with 52 additions and 14 deletions

View file

@ -1614,7 +1614,7 @@ def _gcd_import(name, package=None, level=0):
_imp.release_lock()
message = ("import of {} halted; "
"None in sys.modules".format(name))
raise ImportError(message, name=name)
raise ModuleNotFoundError(message, name=name)
_lock_unlock_module(name)
return module