Implement disabling imports in try/except and * imports, report errors on bad usage of lazy

This commit is contained in:
Dino Viehland 2025-09-29 09:01:41 -07:00
parent 164423b42b
commit 00e7800e4c
11 changed files with 99 additions and 27 deletions

View file

@ -3049,17 +3049,6 @@ _PyEval_LazyImportName(PyThreadState *tstate, PyObject *builtins, PyObject *glob
break;
}
// Always make star imports eager regardless of lazy setting
if (fromlist && PyTuple_Check(fromlist) && PyTuple_GET_SIZE(fromlist) == 1) {
PyObject *item = PyTuple_GET_ITEM(fromlist, 0);
if (PyUnicode_Check(item)) {
const char *item_str = PyUnicode_AsUTF8(item);
if (item_str && strcmp(item_str, "*") == 0) {
lazy = 0; // Force star imports to be eager
}
}
}
if (!lazy) {
// Not a lazy import or lazy imports are disabled, fallback to the regular import
return _PyEval_ImportName(tstate, builtins, globals, locals, name, fromlist, level);