mirror of
https://github.com/python/cpython.git
synced 2025-10-21 22:22:48 +00:00
bpo-32946: Speed up "from ... import ..." from non-packages. (GH-5873)
This commit is contained in:
parent
b931bd0a2f
commit
4e2442505c
4 changed files with 302 additions and 288 deletions
|
@ -1800,10 +1800,21 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals,
|
|||
}
|
||||
}
|
||||
else {
|
||||
final_mod = _PyObject_CallMethodIdObjArgs(interp->importlib,
|
||||
&PyId__handle_fromlist, mod,
|
||||
fromlist, interp->import_func,
|
||||
NULL);
|
||||
_Py_IDENTIFIER(__path__);
|
||||
PyObject *path;
|
||||
if (_PyObject_LookupAttrId(mod, &PyId___path__, &path) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (path) {
|
||||
Py_DECREF(path);
|
||||
final_mod = _PyObject_CallMethodIdObjArgs(
|
||||
interp->importlib, &PyId__handle_fromlist,
|
||||
mod, fromlist, interp->import_func, NULL);
|
||||
}
|
||||
else {
|
||||
final_mod = mod;
|
||||
Py_INCREF(mod);
|
||||
}
|
||||
}
|
||||
|
||||
error:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue