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

Skip to content

Commit 5c08931

Browse files
committed
merge 3.3
2 parents 91c2f37 + 7d11004 commit 5c08931

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

Lib/test/test_import.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,13 @@ def test_bogus_fromlist(self):
324324
except ImportError:
325325
self.fail("fromlist must allow bogus names")
326326

327+
@cpython_only
328+
def test_delete_builtins_import(self):
329+
args = ["-c", "del __builtins__.__import__; import os"]
330+
popen = script_helper.spawn_python(*args)
331+
stdout, stderr = popen.communicate()
332+
self.assertIn(b"ImportError", stdout)
333+
327334

328335
@skip_if_dont_write_bytecode
329336
class FilePermissionTests(unittest.TestCase):

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ What's New in Python 3.4.0 Alpha 1?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #17867: Raise an ImportError if __import__ is not found in __builtins__.
14+
1315
- Issue #17857: Prevent build failures with pre-3.5.0 versions of sqlite3,
1416
such as was shipped with Centos 5 and Mac OS X 10.4.
1517

Python/import.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,8 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *given_globals,
14031403
if (builtins_import == NULL) {
14041404
builtins_import = _PyDict_GetItemId(interp->builtins, &PyId___import__);
14051405
if (builtins_import == NULL) {
1406-
Py_FatalError("__import__ missing");
1406+
PyErr_SetString(PyExc_ImportError, "__import__ not found");
1407+
goto error_with_unlock;
14071408
}
14081409
}
14091410
Py_INCREF(builtins_import);

0 commit comments

Comments
 (0)