diff -r 6d278f426417 Lib/test/test_import.py --- a/Lib/test/test_import.py Fri Jul 05 18:05:29 2013 -1000 +++ b/Lib/test/test_import.py Sat Jul 06 11:45:40 2013 +0200 @@ -1010,6 +1010,22 @@ finally: importlib.SourceLoader.load_module = old_load_module + def test_import_bogus_message(self): + try: + from bogus import foo + except ImportError as e: + self.assertEqual(str(e), "No module named 'bogus'") + else: + self.fail("ImportError should have been raised") + + def test_import_bogus_from_existing_module_message(self): + try: + from re import bogus + except ImportError as e: + self.assertEqual(str(e), "cannot import name 'bogus'") + else: + self.fail("ImportError should have been raised") + if __name__ == '__main__': # Test needs to be a package, so we can do relative imports. diff -r 6d278f426417 Python/ceval.c --- a/Python/ceval.c Fri Jul 05 18:05:29 2013 -1000 +++ b/Python/ceval.c Sat Jul 06 11:45:40 2013 +0200 @@ -4588,7 +4588,7 @@ x = PyObject_GetAttr(v, name); if (x == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) { - PyErr_Format(PyExc_ImportError, "cannot import name %S", name); + PyErr_Format(PyExc_ImportError, "cannot import name %R", name); } return x; }