mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
__import__ is loaded at reification time
This commit is contained in:
parent
c5efb20d48
commit
0c246bc79d
4 changed files with 26 additions and 38 deletions
|
|
@ -3089,14 +3089,6 @@ _PyEval_LazyImportName(PyThreadState *tstate, PyObject *builtins, PyObject *glob
|
|||
return _PyEval_ImportName(tstate, builtins, globals, locals, name, fromlist, level);
|
||||
}
|
||||
|
||||
PyObject *import_func;
|
||||
if (PyMapping_GetOptionalItem(builtins, &_Py_ID(__import__), &import_func) < 0) {
|
||||
goto error;
|
||||
} else if (import_func == NULL) {
|
||||
_PyErr_SetString(tstate, PyExc_ImportError, "__import__ not found");
|
||||
goto error;
|
||||
}
|
||||
|
||||
PyObject *lazy_import_func;
|
||||
if (PyMapping_GetOptionalItem(builtins, &_Py_ID(__lazy_import__), &lazy_import_func) < 0) {
|
||||
goto error;
|
||||
|
|
@ -3116,16 +3108,15 @@ _PyEval_LazyImportName(PyThreadState *tstate, PyObject *builtins, PyObject *glob
|
|||
}
|
||||
|
||||
res = _PyImport_LazyImportModuleLevelObject(
|
||||
tstate, name, import_func, globals, locals, fromlist, ilevel
|
||||
tstate, name, builtins, globals, locals, fromlist, ilevel
|
||||
);
|
||||
goto error;
|
||||
}
|
||||
|
||||
PyObject* args[6] = {name, globals, locals, fromlist, level, import_func};
|
||||
PyObject* args[6] = {name, globals, locals, fromlist, level, builtins};
|
||||
res = PyObject_Vectorcall(lazy_import_func, args, 6, NULL);
|
||||
error:
|
||||
Py_XDECREF(lazy_import_func);
|
||||
Py_XDECREF(import_func);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
@ -3323,7 +3314,7 @@ _PyEval_LazyImportFrom(PyThreadState *tstate, PyObject *v, PyObject *name)
|
|||
if (d->lz_attr != NULL) {
|
||||
if (PyUnicode_Check(d->lz_attr)) {
|
||||
PyObject *from = PyUnicode_FromFormat("%U.%U", d->lz_from, d->lz_attr);
|
||||
ret = _PyLazyImport_New(d->lz_import_func, from, name);
|
||||
ret = _PyLazyImport_New(d->lz_builtins, from, name);
|
||||
Py_DECREF(from);
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -3331,12 +3322,12 @@ _PyEval_LazyImportFrom(PyThreadState *tstate, PyObject *v, PyObject *name)
|
|||
Py_ssize_t dot = PyUnicode_FindChar(d->lz_from, '.', 0, PyUnicode_GET_LENGTH(d->lz_from), 1);
|
||||
if (dot >= 0) {
|
||||
PyObject *from = PyUnicode_Substring(d->lz_from, 0, dot);
|
||||
ret = _PyLazyImport_New(d->lz_import_func, from, name);
|
||||
ret = _PyLazyImport_New(d->lz_builtins, from, name);
|
||||
Py_DECREF(from);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
ret = _PyLazyImport_New(d->lz_import_func, d->lz_from, name);
|
||||
ret = _PyLazyImport_New(d->lz_builtins, d->lz_from, name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue