summaryrefslogtreecommitdiffstats
path: root/Python/import.c
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2012-04-17 23:05:11 (GMT)
committerBrett Cannon <brett@python.org>2012-04-17 23:05:11 (GMT)
commit273323cf68e8d55c67622412ecf531e359a54e11 (patch)
treeddac9de01083d9e7a165c83455493ee31d32ce21 /Python/import.c
parent09b86d1196427f2028d7e072b106847d8c693815 (diff)
downloadcpython-273323cf68e8d55c67622412ecf531e359a54e11.zip
cpython-273323cf68e8d55c67622412ecf531e359a54e11.tar.gz
cpython-273323cf68e8d55c67622412ecf531e359a54e11.tar.bz2
Issue #14592: A relative import will raise a KeyError if __package__
or __name__ are not set in globals. Thanks to Stefan Behnel for the bug report.
Diffstat (limited to 'Python/import.c')
-rw-r--r--Python/import.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/Python/import.c b/Python/import.c
index f3de7d8..3e620b3 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -2355,8 +2355,9 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *given_globals,
}
}
else {
- package = _PyDict_GetItemIdWithError(globals, &PyId___name__);
+ package = _PyDict_GetItemId(globals, &PyId___name__);
if (package == NULL) {
+ PyErr_SetString(PyExc_KeyError, "'__name__' not in globals");
goto error;
}
else if (!PyUnicode_Check(package)) {