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