diff Python/import.c @ 84109:3a50025f1900

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.
author Brett Cannon <brett@python.org>
date Wed, 12 Jun 2013 23:29:18 -0400
parents 82db02a2e023
children a39d2223be23
line wrap: on
line diff
--- a/Python/import.c	Wed Jun 12 21:25:59 2013 -0400
+++ b/Python/import.c	Wed Jun 12 23:29:18 2013 -0400
@@ -1436,7 +1436,8 @@
         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;