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 --git a/Lib/test/test_import.py b/Lib/test/test_import.py
index e6a4379..61df86a 100644
--- a/Lib/test/test_import.py
+++ b/Lib/test/test_import.py
@@ -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 --git a/Misc/ACKS b/Misc/ACKS
index abfa659..ef5fb5c 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -786,6 +786,7 @@
 Tim MacKenzie
 Nick Maclaren
 Don MacMillen
+Tomasz Maćkowiak
 Steve Majewski
 Grzegorz Makarewicz
 David Malcolm
diff --git a/Misc/NEWS b/Misc/NEWS
index 751433f..b65498a 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -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 --git a/Python/ceval.c b/Python/ceval.c
index a53e377..61928e3 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -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;
 }