summaryrefslogtreecommitdiff
path: root/Python/import.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-03-11 10:52:37 +0200
committerGitHub <noreply@github.com>2018-03-11 10:52:37 +0200
commit4e2442505c5e9eec396dcef4d2e6bdd2b6f92fc9 (patch)
treeac8cbbdae9d8772f84254b79d8da9f6df1a2e2b6 /Python/import.c
parentb931bd0a2fe7e9293339019352baf3317166b769 (diff)
downloadcpython-git-4e2442505c5e9eec396dcef4d2e6bdd2b6f92fc9.tar.gz
bpo-32946: Speed up "from ... import ..." from non-packages. (GH-5873)
Diffstat (limited to 'Python/import.c')
-rw-r--r--Python/import.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/Python/import.c b/Python/import.c
index eb5aeac554..9f46da3362 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -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: