changeset: 102378:c88ec1bb67d0 branch: 3.5 parent: 102376:f6a41552a312 user: Serhiy Storchaka date: Sun Jul 17 12:47:17 2016 +0300 files: Misc/NEWS Python/import.c description: 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. diff -r f6a41552a312 -r c88ec1bb67d0 Misc/NEWS --- a/Misc/NEWS Sun Jul 17 11:24:17 2016 +0300 +++ b/Misc/NEWS Sun Jul 17 12:47:17 2016 +0300 @@ -10,6 +10,10 @@ Core and Builtins ----------------- +- 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. + - Issue #27083: Respect the PYTHONCASEOK environment variable under Windows. - Issue #27514: Make having too many statically nested blocks a SyntaxError diff -r f6a41552a312 -r c88ec1bb67d0 Python/import.c --- a/Python/import.c Sun Jul 17 11:24:17 2016 +0300 +++ b/Python/import.c Sun Jul 17 12:47:17 2016 +0300 @@ -1438,6 +1438,7 @@ } else if (!PyUnicode_Check(package)) { PyErr_SetString(PyExc_TypeError, "__name__ must be a string"); + goto error; } Py_INCREF(package); @@ -1525,15 +1526,10 @@ _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);