diff --git a/Python/import.c b/Python/import.c index b078db9a93f..a75be101852 100644 --- a/Python/import.c +++ b/Python/import.c @@ -1637,17 +1637,10 @@ add_lazy_modules(PyThreadState *tstate, PyObject *builtins, PyObject *name, PyOb PyObject *lazy_submodules; if (tstate->interp->eager_imports != NULL) { - int found = PySequence_Contains(tstate->interp->eager_imports, name); - if (found < 0) { - goto error; - } - if (found) { - ret = 0; /* If the module is flagged as eager import, load eagerly */ - goto end; - } + Py_ssize_t size = 0; if (fromlist != NULL && fromlist != Py_None) { assert(PyTuple_CheckExact(fromlist)); - Py_ssize_t size = PyTuple_GET_SIZE(fromlist); + size = PyTuple_GET_SIZE(fromlist); for (Py_ssize_t i = 0; i < size; ++i) { PyObject* item = PyTuple_GET_ITEM(fromlist, i); assert(PyUnicode_Check(item)); @@ -1655,7 +1648,7 @@ add_lazy_modules(PyThreadState *tstate, PyObject *builtins, PyObject *name, PyOb if (from_name == NULL) { goto error; } - found = PySequence_Contains(tstate->interp->eager_imports, from_name); + int found = PySequence_Contains(tstate->interp->eager_imports, from_name); Py_DECREF(from_name); if (found < 0) { goto error; @@ -1666,6 +1659,16 @@ add_lazy_modules(PyThreadState *tstate, PyObject *builtins, PyObject *name, PyOb } } } + if (size == 0) { + int found = PySequence_Contains(tstate->interp->eager_imports, name); + if (found < 0) { + goto error; + } + if (found) { + ret = 0; /* If the module is flagged as eager import, load eagerly */ + goto end; + } + } } lazy_submodules = PyDict_GetItemWithError(lazy_modules, name);