Commits

Victor Stinner committed c4361ba

Issue #3080: Use repr() to format the module name on error

  • Participants
  • Parent commits 238cbd5

Comments (0)

Files changed (3)

File Lib/test/test_pydoc.py

 missing_pattern = "no Python documentation found for '%s'"
 
 # output pattern for module with bad imports
-badimport_pattern = "problem in %s - ImportError: No module named %s"
+badimport_pattern = "problem in %s - ImportError: No module named %r"
 
 def run_pydoc(module_name, *args):
     """

File Lib/unittest/test/test_loader.py

         try:
             loader.loadTestsFromName('sdasfasfasdf')
         except ImportError as e:
-            self.assertEqual(str(e), "No module named sdasfasfasdf")
+            self.assertEqual(str(e), "No module named 'sdasfasfasdf'")
         else:
             self.fail("TestLoader.loadTestsFromName failed to raise ImportError")
 
         try:
             loader.loadTestsFromNames(['sdasfasfasdf'])
         except ImportError as e:
-            self.assertEqual(str(e), "No module named sdasfasfasdf")
+            self.assertEqual(str(e), "No module named 'sdasfasfasdf'")
         else:
             self.fail("TestLoader.loadTestsFromNames failed to raise ImportError")
 

File Python/import.c

             goto error;
         if (Py_VerboseFlag)
             PySys_FormatStderr("import %U # from %R\n",
-                name, pathname);
+                               name, pathname);
         if (cpathname != NULL) {
             PyObject *ro = PySys_GetObject("dont_write_bytecode");
             if (ro == NULL || !PyObject_IsTrue(ro))
     if (m == NULL)
         return NULL;
     if (Py_VerboseFlag)
-        PySys_FormatStderr("import %U # directory %U\n",
-            name, pathname);
+        PySys_FormatStderr("import %U # directory %R\n",
+                           name, pathname);
     file = get_sourcefile(pathname);
     if (file == NULL)
         return NULL;
         Py_DECREF(prefix);
     }
     PyErr_Format(PyExc_ImportError,
-                 "No module named %U", name);
+                 "No module named %R", name);
     return NULL;
 }
 
 
     default:
         PyErr_Format(PyExc_ImportError,
-                     "Don't know how to import %U (type code %d)",
+                     "Don't know how to import %R (type code %d)",
                       name, type);
         m = NULL;
 
         return NULL;
     if (m != PyDict_GetItem(modules, nameobj)) {
         PyErr_Format(PyExc_ImportError,
-                     "reload(): module %U not in sys.modules",
+                     "reload(): module %R not in sys.modules",
                      nameobj);
         Py_DECREF(nameobj);
         return NULL;
         parent = PyDict_GetItem(modules, parentname);
         if (parent == NULL) {
             PyErr_Format(PyExc_ImportError,
-                "reload(): parent %U not in sys.modules",
+                "reload(): parent %R not in sys.modules",
                  parentname);
             Py_DECREF(parentname);
             goto error;