Fix submodules crash

This commit is contained in:
Pablo Galindo Salgado 2025-09-26 22:10:46 +01:00 committed by Dino Viehland
parent 20b14d9ca4
commit 164423b42b

View file

@ -4119,10 +4119,14 @@ _PyImport_LazyImportModuleLevelObject(PyThreadState *tstate,
PyInterpreterState *interp = tstate->interp; PyInterpreterState *interp = tstate->interp;
PyObject *mod = PyImport_GetModule(abs_name); // Don't return early if we have a fromlist - we need to handle the import properly
if (mod != NULL) { // to ensure submodules are loaded
Py_DECREF(abs_name); if (fromlist == NULL || fromlist == Py_None) {
return mod; PyObject *mod = PyImport_GetModule(abs_name);
if (mod != NULL) {
Py_DECREF(abs_name);
return mod;
}
} }
// Check if the filter disables the lazy import // Check if the filter disables the lazy import