[Python-checkins] cpython (merge 3.3 -> default): merge 3.3

benjamin.peterson python-checkins at python.org
Mon Apr 29 15:08:44 CEST 2013


http://hg.python.org/cpython/rev/393723b646a4
changeset:   83550:393723b646a4
parent:      83547:7a45415956b9
parent:      83549:08ce30768003
user:        Benjamin Peterson <benjamin at python.org>
date:        Mon Apr 29 09:08:33 2013 -0400
summary:
  merge 3.3

files:
  Lib/test/test_import.py |  7 +++++++
  Misc/NEWS               |  2 ++
  Python/import.c         |  3 ++-
  3 files changed, 11 insertions(+), 1 deletions(-)


diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py
--- a/Lib/test/test_import.py
+++ b/Lib/test/test_import.py
@@ -324,6 +324,13 @@
         except ImportError:
             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
 class FilePermissionTests(unittest.TestCase):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@
 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,
   such as was shipped with Centos 5 and Mac OS X 10.4.
 
diff --git a/Python/import.c b/Python/import.c
--- a/Python/import.c
+++ b/Python/import.c
@@ -1403,7 +1403,8 @@
     if (builtins_import == NULL) {
         builtins_import = _PyDict_GetItemId(interp->builtins, &PyId___import__);
         if (builtins_import == NULL) {
-            Py_FatalError("__import__ missing");
+            PyErr_SetString(PyExc_ImportError, "__import__ not found");
+            goto error_with_unlock;
         }
     }
     Py_INCREF(builtins_import);

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list