mirror of
https://github.com/python/cpython.git
synced 2025-07-17 08:15:19 +00:00
Issue #15767: Revert 3a50025f1900 for ModuleNotFoundError
This commit is contained in:
parent
45091c0a0c
commit
82da8886cc
10 changed files with 807 additions and 842 deletions
|
@ -619,25 +619,12 @@ PyObject *PyErr_SetFromWindowsErrWithUnicodeFilename(
|
|||
#endif /* MS_WINDOWS */
|
||||
|
||||
PyObject *
|
||||
PyErr_SetImportErrorSubclass(PyObject *exception, PyObject *msg,
|
||||
PyObject *name, PyObject *path)
|
||||
PyErr_SetImportError(PyObject *msg, PyObject *name, PyObject *path)
|
||||
{
|
||||
int issubclass;
|
||||
PyObject *args, *kwargs, *error;
|
||||
|
||||
issubclass = PyObject_IsSubclass(exception, PyExc_ImportError);
|
||||
if (issubclass < 0) {
|
||||
if (msg == NULL)
|
||||
return NULL;
|
||||
}
|
||||
else if (!issubclass) {
|
||||
PyErr_SetString(PyExc_TypeError, "expected a subclass of ImportError");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (msg == NULL) {
|
||||
PyErr_SetString(PyExc_TypeError, "expected a message argument");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
args = PyTuple_New(1);
|
||||
if (args == NULL)
|
||||
|
@ -662,7 +649,7 @@ PyErr_SetImportErrorSubclass(PyObject *exception, PyObject *msg,
|
|||
PyDict_SetItemString(kwargs, "name", name);
|
||||
PyDict_SetItemString(kwargs, "path", path);
|
||||
|
||||
error = PyObject_Call(exception, args, kwargs);
|
||||
error = PyObject_Call(PyExc_ImportError, args, kwargs);
|
||||
if (error != NULL) {
|
||||
PyErr_SetObject((PyObject *)Py_TYPE(error), error);
|
||||
Py_DECREF(error);
|
||||
|
@ -674,12 +661,6 @@ PyErr_SetImportErrorSubclass(PyObject *exception, PyObject *msg,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
PyObject *
|
||||
PyErr_SetImportError(PyObject *msg, PyObject *name, PyObject *path)
|
||||
{
|
||||
return PyErr_SetImportErrorSubclass(PyExc_ImportError, msg, name, path);
|
||||
}
|
||||
|
||||
void
|
||||
_PyErr_BadInternalCall(const char *filename, int lineno)
|
||||
{
|
||||
|
|
|
@ -1428,8 +1428,7 @@ 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_SetImportErrorSubclass(PyExc_ModuleNotFoundError, msg,
|
||||
abs_name, NULL);
|
||||
PyErr_SetImportError(msg, abs_name, NULL);
|
||||
Py_DECREF(msg);
|
||||
}
|
||||
mod = NULL;
|
||||
|
|
1587
Python/importlib.h
1587
Python/importlib.h
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue