diff Python/import.c @ 76380:68f9ad6a3b13

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.
author Brett Cannon <brett@python.org>
date Tue, 17 Apr 2012 19:05:11 -0400
parents 7a32b9380ffd
children 66bd85bcf916
line wrap: on
line diff
--- a/Python/import.c	Tue Apr 17 16:57:09 2012 -0500
+++ b/Python/import.c	Tue Apr 17 19:05:11 2012 -0400
@@ -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)) {