diff -r 00991aa5fdb5 Lib/os.py --- a/Lib/os.py Sat Jun 04 10:19:27 2016 -0700 +++ b/Lib/os.py Sat Jun 04 10:35:27 2016 -0700 @@ -889,7 +889,7 @@ return filename.encode(encoding, errors) else: raise TypeError("expected str, bytes or os.PathLike object, not " - + path_type.__name__) + + type(filename).__name__) def fsdecode(filename): """ @@ -905,7 +905,7 @@ return filename.decode(encoding, errors) else: raise TypeError("expected str, bytes or os.PathLike object, not " - + path_type.__name__) + + type(filename).__name__) return fsencode, fsdecode diff -r 00991aa5fdb5 Lib/test/test_os.py --- a/Lib/test/test_os.py Sat Jun 04 10:19:27 2016 -0700 +++ b/Lib/test/test_os.py Sat Jun 04 10:35:27 2016 -0700 @@ -3121,6 +3121,12 @@ self.assertEqual(b"path/like/object", os.fsencode(pathlike)) self.assertEqual("path/like/object", os.fsdecode(pathlike)) + message = 'expected str, bytes or os.PathLike object, not' + for fn in (os.fsencode, os.fsdecode): + for obj in (Pathlike(None), None): + with self.assertRaisesRegex(TypeError, message): + fn(obj) + def test_garbage_in_exception_out(self): vapor = type('blah', (), {}) for o in int, type, os, vapor():