summaryrefslogtreecommitdiff
path: root/Python
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2012-04-17 19:05:11 -0400
committerBrett Cannon <brett@python.org>2012-04-17 19:05:11 -0400
commit9459c0f7879ddbb51a8e8da936c1c41113b077fa (patch)
tree0d9aa81c5f5c9c54e3118e9ae861c21033256444 /Python
parent5d8520121e1ea38bcfe37258449a946ee328cac1 (diff)
downloadcpython-9459c0f7879ddbb51a8e8da936c1c41113b077fa.tar.gz
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')
-rw-r--r--Python/import.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/Python/import.c b/Python/import.c
index f3de7d8262..3e620b3706 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)) {