diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2016-09-07 16:56:15 -0700 |
---|---|---|
committer | Eric Snow <ericsnowcurrently@gmail.com> | 2016-09-07 16:56:15 -0700 |
commit | 46f97b85a8ce9ae67b6e4bc32e94f7827df7bab7 (patch) | |
tree | e814eb2b2365001ddbc119372da70eed52f2aeb5 /Python/errors.c | |
parent | c943265ba56e7ce7e2fe79fdecfc6670e10e5467 (diff) | |
download | cpython-git-46f97b85a8ce9ae67b6e4bc32e94f7827df7bab7.tar.gz |
Issue #15767: Use ModuleNotFoundError.
Diffstat (limited to 'Python/errors.c')
-rw-r--r-- | Python/errors.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/Python/errors.c b/Python/errors.c index e6285e8b3b..13ae6b4561 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -697,27 +697,37 @@ PyObject *PyErr_SetFromWindowsErrWithUnicodeFilename( #endif /* MS_WINDOWS */ PyObject * -PyErr_SetImportError(PyObject *msg, PyObject *name, PyObject *path) +PyErr_SetImportErrorSubclass(PyObject *exception, PyObject *msg, + PyObject *name, PyObject *path) { + int issubclass; PyObject *kwargs, *error; - if (msg == NULL) { + issubclass = PyObject_IsSubclass(exception, PyExc_ImportError); + if (issubclass < 0) { + return NULL; + } + else if (!issubclass) { + PyErr_SetString(PyExc_TypeError, "expected a subclass of ImportError"); return NULL; } - kwargs = PyDict_New(); - if (kwargs == NULL) { + if (msg == NULL) { + PyErr_SetString(PyExc_TypeError, "expected a message argument"); return NULL; } if (name == NULL) { name = Py_None; } - if (path == NULL) { path = Py_None; } + kwargs = PyDict_New(); + if (kwargs == NULL) { + return NULL; + } if (PyDict_SetItemString(kwargs, "name", name) < 0) { goto done; } @@ -725,7 +735,7 @@ PyErr_SetImportError(PyObject *msg, PyObject *name, PyObject *path) goto done; } - error = _PyObject_FastCallDict(PyExc_ImportError, &msg, 1, kwargs); + error = _PyObject_FastCallDict(exception, &msg, 1, kwargs); if (error != NULL) { PyErr_SetObject((PyObject *)Py_TYPE(error), error); Py_DECREF(error); @@ -736,6 +746,12 @@ done: 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) { |