mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
Move eager check for from imports into import from
This commit is contained in:
parent
7d07ae13d7
commit
c63198cba4
5 changed files with 37 additions and 9 deletions
|
|
@ -4221,16 +4221,8 @@ _PyImport_LazyImportModuleLevelObject(PyThreadState *tstate,
|
|||
}
|
||||
|
||||
PyInterpreterState *interp = tstate->interp;
|
||||
_PyInterpreterFrame *frame = _PyEval_GetFrame();
|
||||
assert(frame->f_globals == frame->f_locals); // should only be called in global scope
|
||||
|
||||
PyObject *mod = PyImport_GetModule(abs_name);
|
||||
bool already_exists = mod != NULL;
|
||||
Py_XDECREF(mod);
|
||||
if (mod != NULL) {
|
||||
return PyImport_ImportModuleLevelObject(name, globals, locals, fromlist, level);
|
||||
}
|
||||
|
||||
// Check if the filter disables the lazy import
|
||||
PyObject *filter = LAZY_IMPORTS_FILTER(interp);
|
||||
if (filter != NULL) {
|
||||
|
|
@ -4262,7 +4254,7 @@ _PyImport_LazyImportModuleLevelObject(PyThreadState *tstate,
|
|||
}
|
||||
|
||||
PyObject *res = _PyLazyImport_New(import_func, abs_name, fromlist);
|
||||
if (!already_exists && register_lazy_on_parent(tstate, abs_name, import_func) < 0) {
|
||||
if (register_lazy_on_parent(tstate, abs_name, import_func) < 0) {
|
||||
Py_DECREF(res);
|
||||
res = NULL;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue