diff -r 470954641f3b Lib/test/test_os.py --- a/Lib/test/test_os.py Sun Jun 05 12:07:48 2016 +0000 +++ b/Lib/test/test_os.py Sun Jun 05 09:55:44 2016 -0700 @@ -3142,6 +3142,12 @@ for o in int, type, os, vapor(): self.assertRaises(TypeError, os.fspath, o) + def test_exception_message(self): + with self.assertRaisesRegex( + TypeError, + "expected str, bytes or os.PathLike object, not int"): + os.fspath(3) + def test_argument_required(self): with self.assertRaises(TypeError): os.fspath() diff -r 470954641f3b Modules/posixmodule.c --- a/Modules/posixmodule.c Sun Jun 05 12:07:48 2016 +0000 +++ b/Modules/posixmodule.c Sun Jun 05 09:55:44 2016 -0700 @@ -12307,8 +12307,8 @@ if (NULL == func) { return PyErr_Format(PyExc_TypeError, "expected str, bytes or os.PathLike object, " - "not %S", - path->ob_type); + "not %.200s", + Py_TYPE(path)->tp_name); } path_repr = PyObject_CallFunctionObjArgs(func, NULL);