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