mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-91058: Add error suggestions to 'import from' import errors (#98305)
This commit is contained in:
parent
1f737edb67
commit
7cfbb49fcd
11 changed files with 235 additions and 14 deletions
|
@ -6900,7 +6900,7 @@ import_from(PyThreadState *tstate, PyObject *v, PyObject *name)
|
|||
name, pkgname_or_unknown
|
||||
);
|
||||
/* NULL checks for errmsg and pkgname done by PyErr_SetImportError. */
|
||||
PyErr_SetImportError(errmsg, pkgname, NULL);
|
||||
_PyErr_SetImportErrorWithNameFrom(errmsg, pkgname, NULL, name);
|
||||
}
|
||||
else {
|
||||
PyObject *spec = PyObject_GetAttr(v, &_Py_ID(__spec__));
|
||||
|
@ -6913,7 +6913,7 @@ import_from(PyThreadState *tstate, PyObject *v, PyObject *name)
|
|||
|
||||
errmsg = PyUnicode_FromFormat(fmt, name, pkgname_or_unknown, pkgpath);
|
||||
/* NULL checks for errmsg and pkgname done by PyErr_SetImportError. */
|
||||
PyErr_SetImportError(errmsg, pkgname, pkgpath);
|
||||
_PyErr_SetImportErrorWithNameFrom(errmsg, pkgname, pkgpath, name);
|
||||
}
|
||||
|
||||
Py_XDECREF(errmsg);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue