diff options
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/Python/import.c b/Python/import.c index d4f57835d3..e96c7e4bc6 100644 --- a/Python/import.c +++ b/Python/import.c @@ -3019,15 +3019,22 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *given_globals, Py_DECREF(partition); if (level == 0) { - final_mod = PyDict_GetItem(interp->modules, front); - Py_DECREF(front); - if (final_mod == NULL) { - PyErr_Format(PyExc_KeyError, - "%R not in sys.modules as expected", front); + if (PyUnicode_GET_LENGTH(name) == + PyUnicode_GET_LENGTH(front)) { + final_mod = mod; } else { - Py_INCREF(final_mod); + final_mod = PyDict_GetItem(interp->modules, front); + if (final_mod == NULL) { + PyErr_Format(PyExc_KeyError, + "%R not in sys.modules as expected", front); + } + } + Py_DECREF(front); + if (final_mod == NULL) { + goto error_with_unlock; } + Py_INCREF(final_mod); } else { Py_ssize_t cut_off = PyUnicode_GetLength(name) - |