mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
Implement disabling imports in try/except and * imports, report errors on bad usage of lazy
This commit is contained in:
parent
164423b42b
commit
00e7800e4c
11 changed files with 99 additions and 27 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue