mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
Add lazy import filter
This commit is contained in:
parent
9eef03cc80
commit
de281fd894
21 changed files with 343 additions and 11 deletions
|
|
@ -3027,8 +3027,25 @@ _PyEval_ImportName(PyThreadState *tstate, PyObject *builtins, PyObject *globals,
|
|||
|
||||
PyObject *
|
||||
_PyEval_LazyImportName(PyThreadState *tstate, PyObject *builtins, PyObject *globals,
|
||||
PyObject *locals, PyObject *name, PyObject *fromlist, PyObject *level)
|
||||
PyObject *locals, PyObject *name, PyObject *fromlist, PyObject *level, int lazy)
|
||||
{
|
||||
// Check if global policy overrides the local syntax
|
||||
switch (PyImport_LazyImportsEnabled()) {
|
||||
case PyLazyImportsMode_ForcedOff:
|
||||
lazy = 0;
|
||||
break;
|
||||
case PyLazyImportsMode_ForcedOn:
|
||||
lazy = 1;
|
||||
break;
|
||||
case PyLazyImportsMode_Default:
|
||||
break;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
PyObject *import_func;
|
||||
if (PyMapping_GetOptionalItem(builtins, &_Py_ID(__lazy_import__), &import_func) < 0) {
|
||||
return NULL;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue