diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-07-17 09:47:17 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-07-17 09:47:17 (GMT) |
commit | b3b65e618c31e37458d5da46c8216f7c0404f547 (patch) | |
tree | 200f7ecc20f9c7391875e718483fe6ecd665bdff /Python/import.c | |
parent | dec25afab1c325c28621dda3ba2b32dbc200c8b3 (diff) | |
download | cpython-b3b65e618c31e37458d5da46c8216f7c0404f547.zip cpython-b3b65e618c31e37458d5da46c8216f7c0404f547.tar.gz cpython-b3b65e618c31e37458d5da46c8216f7c0404f547.tar.bz2 |
Issue #27419: Standard __import__() no longer look up "__import__" in globals
or builtins for importing submodules or "from import". Fixed handling an
error of non-string package name.
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 1312fd0..c1dc9a0 100644 --- a/Python/import.c +++ b/Python/import.c @@ -1438,6 +1438,7 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *given_globals, } else if (!PyUnicode_Check(package)) { PyErr_SetString(PyExc_TypeError, "__name__ must be a string"); + goto error; } Py_INCREF(package); @@ -1525,15 +1526,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); |