Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7905f99

Browse files
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__.
2 parents 3410c01 + b3b65e6 commit 7905f99

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

Misc/NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ What's New in Python 3.6.0 alpha 4
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #27419: Standard __import__() no longer look up "__import__" in globals
14+
or builtins for importing submodules or "from import". Fixed a crash if
15+
raise a warning about unabling to resolve package from __spec__ or
16+
__package__.
17+
1318
- Issue #27083: Respect the PYTHONCASEOK environment variable under Windows.
1419

1520
- Issue #27514: Make having too many statically nested blocks a SyntaxError

Python/import.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,7 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *given_globals,
14521452
}
14531453
}
14541454
else {
1455+
package = NULL;
14551456
if (PyErr_WarnEx(PyExc_ImportWarning,
14561457
"can't resolve package from __spec__ or __package__, "
14571458
"falling back on __name__ and __path__", 1) < 0) {
@@ -1556,15 +1557,10 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *given_globals,
15561557
_PyImport_AcquireLock();
15571558
#endif
15581559
/* From this point forward, goto error_with_unlock! */
1559-
if (PyDict_Check(globals)) {
1560-
builtins_import = _PyDict_GetItemId(globals, &PyId___import__);
1561-
}
1560+
builtins_import = _PyDict_GetItemId(interp->builtins_copy, &PyId___import__);
15621561
if (builtins_import == NULL) {
1563-
builtins_import = _PyDict_GetItemId(interp->builtins, &PyId___import__);
1564-
if (builtins_import == NULL) {
1565-
PyErr_SetString(PyExc_ImportError, "__import__ not found");
1566-
goto error_with_unlock;
1567-
}
1562+
PyErr_SetString(PyExc_ImportError, "__import__ not found");
1563+
goto error_with_unlock;
15681564
}
15691565
Py_INCREF(builtins_import);
15701566

0 commit comments

Comments
 (0)