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.
This commit is contained in:
Brett Cannon 2012-04-17 19:05:11 -04:00
parent 09b86d1196
commit 273323cf68
3 changed files with 10 additions and 1 deletions

View file

@ -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)) {