diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-07-17 12:51:34 +0300 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-07-17 12:51:34 +0300 |
commit | a6fcc4ea07b6253c97d4f37c47643a301653b31e (patch) | |
tree | cf95a00691d24a66d133743ae5ac6822a6733d52 /Python/import.c | |
parent | 5a515b0afe6a2bc273211ba47fd8fe04c56517c7 (diff) | |
parent | 65c9dc2b8c93e4bbcf92c1c7729c4ce831dae352 (diff) | |
download | cpython-a6fcc4ea07b6253c97d4f37c47643a301653b31e.tar.gz |
Issue #27419: Standard __import__() no longer look up "__import__" in globals
or builtins for importing submodules or "from import". Fixed a crash if
raise a warning about unabling to resolve package from __spec__ or
__package__.
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/Python/import.c b/Python/import.c index bdc7e4cfa7..7a2c92eef9 100644 --- a/Python/import.c +++ b/Python/import.c @@ -1452,6 +1452,7 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *given_globals, } } else { + package = NULL; if (PyErr_WarnEx(PyExc_ImportWarning, "can't resolve package from __spec__ or __package__, " "falling back on __name__ and __path__", 1) < 0) { @@ -1556,15 +1557,10 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *given_globals, _PyImport_AcquireLock(); #endif /* From this point forward, goto error_with_unlock! */ - if (PyDict_Check(globals)) { - builtins_import = _PyDict_GetItemId(globals, &PyId___import__); - } + builtins_import = _PyDict_GetItemId(interp->builtins_copy, &PyId___import__); if (builtins_import == NULL) { - builtins_import = _PyDict_GetItemId(interp->builtins, &PyId___import__); - if (builtins_import == NULL) { - PyErr_SetString(PyExc_ImportError, "__import__ not found"); - goto error_with_unlock; - } + PyErr_SetString(PyExc_ImportError, "__import__ not found"); + goto error_with_unlock; } Py_INCREF(builtins_import); |