Skip to content

Commit 07a633f

Browse files
pablogsalDinoV
authored andcommitted
Draft: force * imports to be eager
1 parent 73de8d0 commit 07a633f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Python/ceval.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3049,6 +3049,17 @@ _PyEval_LazyImportName(PyThreadState *tstate, PyObject *builtins, PyObject *glob
30493049
break;
30503050
}
30513051

3052+
// Always make star imports eager regardless of lazy setting
3053+
if (fromlist && PyTuple_Check(fromlist) && PyTuple_GET_SIZE(fromlist) == 1) {
3054+
PyObject *item = PyTuple_GET_ITEM(fromlist, 0);
3055+
if (PyUnicode_Check(item)) {
3056+
const char *item_str = PyUnicode_AsUTF8(item);
3057+
if (item_str && strcmp(item_str, "*") == 0) {
3058+
lazy = 0; // Force star imports to be eager
3059+
}
3060+
}
3061+
}
3062+
30523063
if (!lazy) {
30533064
// Not a lazy import or lazy imports are disabled, fallback to the regular import
30543065
return _PyEval_ImportName(tstate, builtins, globals, locals, name, fromlist, level);

0 commit comments

Comments
 (0)