mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
raise an ImportError (rather than fatal) when __import__ is not found in __builtins__ (closes #17867)
This commit is contained in:
parent
775ccdf1fc
commit
7d110042c5
3 changed files with 11 additions and 1 deletions
|
@ -324,6 +324,13 @@ class ImportTests(unittest.TestCase):
|
||||||
except ImportError:
|
except ImportError:
|
||||||
self.fail("fromlist must allow bogus names")
|
self.fail("fromlist must allow bogus names")
|
||||||
|
|
||||||
|
@cpython_only
|
||||||
|
def test_delete_builtins_import(self):
|
||||||
|
args = ["-c", "del __builtins__.__import__; import os"]
|
||||||
|
popen = script_helper.spawn_python(*args)
|
||||||
|
stdout, stderr = popen.communicate()
|
||||||
|
self.assertIn(b"ImportError", stdout)
|
||||||
|
|
||||||
|
|
||||||
@skip_if_dont_write_bytecode
|
@skip_if_dont_write_bytecode
|
||||||
class FilePermissionTests(unittest.TestCase):
|
class FilePermissionTests(unittest.TestCase):
|
||||||
|
|
|
@ -12,6 +12,8 @@ What's New in Python 3.3.2?
|
||||||
Core and Builtins
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Issue #17867: Raise an ImportError if __import__ is not found in __builtins__.
|
||||||
|
|
||||||
- Issue #17857: Prevent build failures with pre-3.5.0 versions of sqlite3,
|
- Issue #17857: Prevent build failures with pre-3.5.0 versions of sqlite3,
|
||||||
such as was shipped with Centos 5 and Mac OS X 10.4.
|
such as was shipped with Centos 5 and Mac OS X 10.4.
|
||||||
|
|
||||||
|
|
|
@ -1389,7 +1389,8 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *given_globals,
|
||||||
if (builtins_import == NULL) {
|
if (builtins_import == NULL) {
|
||||||
builtins_import = _PyDict_GetItemId(interp->builtins, &PyId___import__);
|
builtins_import = _PyDict_GetItemId(interp->builtins, &PyId___import__);
|
||||||
if (builtins_import == NULL) {
|
if (builtins_import == NULL) {
|
||||||
Py_FatalError("__import__ missing");
|
PyErr_SetString(PyExc_ImportError, "__import__ not found");
|
||||||
|
goto error_with_unlock;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Py_INCREF(builtins_import);
|
Py_INCREF(builtins_import);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue