diff options
author | Brett Cannon <brett@python.org> | 2013-06-12 23:29:18 -0400 |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2013-06-12 23:29:18 -0400 |
commit | 8f5ac5106eb24dd8bda91f25e993a90a820a2d5c (patch) | |
tree | 49b910fbfa1af58f0c017d42c84d507b338d7bb2 /Python/import.c | |
parent | 3e9a9ae09d6fc9169b01cba3efd1ae03ab40b237 (diff) | |
download | cpython-git-8f5ac5106eb24dd8bda91f25e993a90a820a2d5c.tar.gz |
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.
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/Python/import.c b/Python/import.c index 0bb46d2e1e..fad54e66ce 100644 --- a/Python/import.c +++ b/Python/import.c @@ -1436,7 +1436,8 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *given_globals, PyObject *msg = PyUnicode_FromFormat("import of %R halted; " "None in sys.modules", abs_name); if (msg != NULL) { - PyErr_SetImportError(msg, abs_name, NULL); + PyErr_SetImportErrorSubclass(PyExc_ModuleNotFoundError, msg, + abs_name, NULL); Py_DECREF(msg); } mod = NULL; |