diff options
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 19 |
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: |