(original) (raw)

changeset: 84583:c3f9292c8efe user: Brett Cannon brett@python.org date: Fri Jul 12 11:22:26 2013 -0400 files: Lib/test/test_import.py Misc/ACKS Misc/NEWS Python/ceval.c description: Issue #18342: Use the repr of a module name for ``from ... import ...`` when an ImportError occurs. Other cases had already been switched over to using the repr. Thanks to Tomasz Maćkowiak for the patch. diff -r 33d379c2bb79 -r c3f9292c8efe Lib/test/test_import.py --- a/Lib/test/test_import.py Fri Jul 12 11:04:23 2013 -0400 +++ b/Lib/test/test_import.py Fri Jul 12 11:22:26 2013 -0400 @@ -321,6 +321,14 @@ stdout, stderr = popen.communicate() self.assertIn(b"ImportError", stdout) + def test_from_import_message_for_nonexistent_module(self): + with self.assertRaisesRegexp(ImportError, "^No module named 'bogus'"): + from bogus import foo + + def test_from_import_message_for_existing_module(self): + with self.assertRaisesRegexp(ImportError, "^cannot import name 'bogus'"): + from re import bogus + @skip_if_dont_write_bytecode class FilePermissionTests(unittest.TestCase): diff -r 33d379c2bb79 -r c3f9292c8efe Misc/ACKS --- a/Misc/ACKS Fri Jul 12 11:04:23 2013 -0400 +++ b/Misc/ACKS Fri Jul 12 11:22:26 2013 -0400 @@ -786,6 +786,7 @@ Tim MacKenzie Nick Maclaren Don MacMillen +Tomasz Maćkowiak Steve Majewski Grzegorz Makarewicz David Malcolm diff -r 33d379c2bb79 -r c3f9292c8efe Misc/NEWS --- a/Misc/NEWS Fri Jul 12 11:04:23 2013 -0400 +++ b/Misc/NEWS Fri Jul 12 11:22:26 2013 -0400 @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #18342: Use the repr of a module name when an import fails when using + ``from ... import ...``. + - Issue #17872: Fix a segfault in marshal.load() when input stream returns more bytes than requested. diff -r 33d379c2bb79 -r c3f9292c8efe Python/ceval.c --- a/Python/ceval.c Fri Jul 12 11:04:23 2013 -0400 +++ b/Python/ceval.c Fri Jul 12 11:22:26 2013 -0400 @@ -4602,7 +4602,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; } /brett@python.org