mirror of
https://github.com/python/cpython.git
synced 2025-10-06 15:11:58 +00:00
gh-112660: Do not clear arbitrary errors on import (GH-112661)
Previously arbitrary errors could be cleared during formatting error messages for ImportError or AttributeError for modules. Now all unexpected errors are reported.
This commit is contained in:
parent
953ee622b3
commit
8660fb7fd7
4 changed files with 72 additions and 58 deletions
|
@ -252,18 +252,21 @@ import_ensure_initialized(PyInterpreterState *interp, PyObject *mod, PyObject *n
|
|||
NOTE: because of this, initializing must be set *before*
|
||||
stuffing the new module in sys.modules.
|
||||
*/
|
||||
spec = PyObject_GetAttr(mod, &_Py_ID(__spec__));
|
||||
int busy = _PyModuleSpec_IsInitializing(spec);
|
||||
Py_XDECREF(spec);
|
||||
if (busy) {
|
||||
/* Wait until module is done importing. */
|
||||
PyObject *value = PyObject_CallMethodOneArg(
|
||||
IMPORTLIB(interp), &_Py_ID(_lock_unlock_module), name);
|
||||
if (value == NULL) {
|
||||
return -1;
|
||||
}
|
||||
Py_DECREF(value);
|
||||
int rc = PyObject_GetOptionalAttr(mod, &_Py_ID(__spec__), &spec);
|
||||
if (rc > 0) {
|
||||
rc = _PyModuleSpec_IsInitializing(spec);
|
||||
Py_DECREF(spec);
|
||||
}
|
||||
if (rc <= 0) {
|
||||
return rc;
|
||||
}
|
||||
/* Wait until module is done importing. */
|
||||
PyObject *value = PyObject_CallMethodOneArg(
|
||||
IMPORTLIB(interp), &_Py_ID(_lock_unlock_module), name);
|
||||
if (value == NULL) {
|
||||
return -1;
|
||||
}
|
||||
Py_DECREF(value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue