mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
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:
parent
09b86d1196
commit
273323cf68
3 changed files with 10 additions and 1 deletions
|
@ -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)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue