diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-10-30 11:19:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-30 11:19:51 (GMT) |
commit | 3e429dcc242e48fa4cbb1a91cf7c416c37b97b4e (patch) | |
tree | 6e84750ed25ac0ec74e491a4261ce4338bff4fa0 /Python/import.c | |
parent | 95b6acf951fa7f503a3cc5ce7d969d7bcf2f95c9 (diff) | |
download | cpython-3e429dcc242e48fa4cbb1a91cf7c416c37b97b4e.zip cpython-3e429dcc242e48fa4cbb1a91cf7c416c37b97b4e.tar.gz cpython-3e429dcc242e48fa4cbb1a91cf7c416c37b97b4e.tar.bz2 |
bpo-33237: Improve AttributeError message for partially initialized module. (GH-6398)
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 30 |
1 files changed, 9 insertions, 21 deletions
diff --git a/Python/import.c b/Python/import.c index 1e8c07b..e761f65 100644 --- a/Python/import.c +++ b/Python/import.c @@ -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); |