Skip to content

Commit 164423b

Browse files
pablogsalDinoV
authored andcommitted
Fix submodules crash
1 parent 20b14d9 commit 164423b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Python/import.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4119,10 +4119,14 @@ _PyImport_LazyImportModuleLevelObject(PyThreadState *tstate,
41194119

41204120
PyInterpreterState *interp = tstate->interp;
41214121

4122-
PyObject *mod = PyImport_GetModule(abs_name);
4123-
if (mod != NULL) {
4124-
Py_DECREF(abs_name);
4125-
return mod;
4122+
// Don't return early if we have a fromlist - we need to handle the import properly
4123+
// to ensure submodules are loaded
4124+
if (fromlist == NULL || fromlist == Py_None) {
4125+
PyObject *mod = PyImport_GetModule(abs_name);
4126+
if (mod != NULL) {
4127+
Py_DECREF(abs_name);
4128+
return mod;
4129+
}
41264130
}
41274131

41284132
// Check if the filter disables the lazy import

0 commit comments

Comments
 (0)