[Python-checkins] cpython (merge 3.5 -> default): Issue #27419: Standard __import__() no longer look up "__import__" in globals

serhiy.storchaka python-checkins at python.org
Sun Jul 17 05:52:29 EDT 2016


https://hg.python.org/cpython/rev/d87f99e297d5
changeset: 102379:d87f99e297d5
parent: 102377:df8857c6f3eb
parent: 102378:c88ec1bb67d0
user: Serhiy Storchaka <storchaka at gmail.com>
date: Sun Jul 17 12:51:34 2016 +0300
summary:
 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__.
files:
 Misc/NEWS | 5 +++++
 Python/import.c | 12 ++++--------
 2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,11 @@
 Core and Builtins
 -----------------
 
+- 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__.
+
 - Issue #27083: Respect the PYTHONCASEOK environment variable under Windows.
 
 - Issue #27514: Make having too many statically nested blocks a SyntaxError
diff --git a/Python/import.c b/Python/import.c
--- a/Python/import.c
+++ b/Python/import.c
@@ -1452,6 +1452,7 @@
 }
 }
 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_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);
 
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /