mirror of
https://github.com/python/cpython.git
synced 2025-07-15 23:35:23 +00:00
bpo-33237: Improve AttributeError message for partially initialized module. (GH-6398)
This commit is contained in:
parent
95b6acf951
commit
3e429dcc24
7 changed files with 67 additions and 23 deletions
|
@ -1721,11 +1721,8 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals,
|
|||
mod = PyImport_GetModule(abs_name);
|
||||
if (mod != NULL && mod != Py_None) {
|
||||
_Py_IDENTIFIER(__spec__);
|
||||
_Py_IDENTIFIER(_initializing);
|
||||
_Py_IDENTIFIER(_lock_unlock_module);
|
||||
PyObject *value = NULL;
|
||||
PyObject *spec;
|
||||
int initializing = 0;
|
||||
|
||||
/* Optimization: only call _bootstrap._lock_unlock_module() if
|
||||
__spec__._initializing is true.
|
||||
|
@ -1733,26 +1730,17 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals,
|
|||
stuffing the new module in sys.modules.
|
||||
*/
|
||||
spec = _PyObject_GetAttrId(mod, &PyId___spec__);
|
||||
if (spec != NULL) {
|
||||
value = _PyObject_GetAttrId(spec, &PyId__initializing);
|
||||
Py_DECREF(spec);
|
||||
}
|
||||
if (value == NULL)
|
||||
PyErr_Clear();
|
||||
else {
|
||||
initializing = PyObject_IsTrue(value);
|
||||
Py_DECREF(value);
|
||||
if (initializing == -1)
|
||||
PyErr_Clear();
|
||||
if (initializing > 0) {
|
||||
value = _PyObject_CallMethodIdObjArgs(interp->importlib,
|
||||
&PyId__lock_unlock_module, abs_name,
|
||||
NULL);
|
||||
if (value == NULL)
|
||||
goto error;
|
||||
Py_DECREF(value);
|
||||
if (_PyModuleSpec_IsInitializing(spec)) {
|
||||
PyObject *value = _PyObject_CallMethodIdObjArgs(interp->importlib,
|
||||
&PyId__lock_unlock_module, abs_name,
|
||||
NULL);
|
||||
if (value == NULL) {
|
||||
Py_DECREF(spec);
|
||||
goto error;
|
||||
}
|
||||
Py_DECREF(value);
|
||||
}
|
||||
Py_XDECREF(spec);
|
||||
}
|
||||
else {
|
||||
Py_XDECREF(mod);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue