summaryrefslogtreecommitdiffstats
path: root/Python/import.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-05-07 19:41:59 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-05-07 19:41:59 (GMT)
commit6efa50a384f61155cd5315cd32f0f8775fe124c5 (patch)
tree2cc831c060e953beb452ec4b33e199e2c06f25d9 /Python/import.c
parent943cab2fec8e7fb3232e72d9f1ca6535674e746a (diff)
downloadcpython-6efa50a384f61155cd5315cd32f0f8775fe124c5.zip
cpython-6efa50a384f61155cd5315cd32f0f8775fe124c5.tar.gz
cpython-6efa50a384f61155cd5315cd32f0f8775fe124c5.tar.bz2
Issue #14583: Fix importlib bug when a package's __init__.py would first import one of its modules then raise an error.
Diffstat (limited to 'Python/import.c')
-rw-r--r--Python/import.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/Python/import.c b/Python/import.c
index fd42a89..a8b1aa3 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -1633,19 +1633,20 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *given_globals,
goto error_with_unlock;
}
+ if (PyUnicode_GET_LENGTH(PyTuple_GET_ITEM(partition, 1)) == 0) {
+ /* No dot in module name, simple exit */
+ Py_DECREF(partition);
+ final_mod = mod;
+ Py_INCREF(mod);
+ goto exit_with_unlock;
+ }
+
front = PyTuple_GET_ITEM(partition, 0);
Py_INCREF(front);
Py_DECREF(partition);
if (level == 0) {
- final_mod = PyDict_GetItem(interp->modules, front);
- if (final_mod == NULL) {
- PyErr_Format(PyExc_KeyError,
- "%R not in sys.modules as expected", front);
- }
- else {
- Py_INCREF(final_mod);
- }
+ final_mod = PyObject_CallFunctionObjArgs(builtins_import, front, NULL);
Py_DECREF(front);
}
else {
@@ -1682,6 +1683,8 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *given_globals,
fromlist, builtins_import,
NULL);
}
+
+ exit_with_unlock:
error_with_unlock:
#ifdef WITH_THREAD
if (_PyImport_ReleaseLock() < 0) {