summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-07-17 09:51:34 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-07-17 09:51:34 (GMT)
commit7905f99a27c82fb31218805d4b859fc0dbefbcec (patch)
tree5db7857fd2c7587e0772e1584ad558bc64d541dc
parent3410c01d83d70ceef48b735c247aebd2d5bd3411 (diff)
parentb3b65e618c31e37458d5da46c8216f7c0404f547 (diff)
downloadcpython-7905f99a27c82fb31218805d4b859fc0dbefbcec.zip
cpython-7905f99a27c82fb31218805d4b859fc0dbefbcec.tar.gz
cpython-7905f99a27c82fb31218805d4b859fc0dbefbcec.tar.bz2
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__.
-rw-r--r--Misc/NEWS5
-rw-r--r--Python/import.c12
2 files changed, 9 insertions, 8 deletions
diff --git a/Misc/NEWS b/Misc/NEWS
index 848700a..1d6f5c3 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,11 @@ What's New in Python 3.6.0 alpha 4
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
index bdc7e4c..7a2c92e 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);