diff -r 7f3ebd86464b Lib/test/test_os.py --- a/Lib/test/test_os.py Thu Jun 02 15:28:29 2016 -0700 +++ b/Lib/test/test_os.py Thu Jun 02 16:58:00 2016 -0700 @@ -2946,6 +2946,10 @@ entry = self.create_file_entry() self.assertEqual(repr(entry), "") + def test_fspath_protocol(self): + entry = self.create_file_entry() + self.assertEqual(os.fspath(entry), os.path.join(self.path, 'file.txt')) + def test_removed_dir(self): path = os.path.join(self.path, 'dir') diff -r 7f3ebd86464b Modules/posixmodule.c --- a/Modules/posixmodule.c Thu Jun 02 15:28:29 2016 -0700 +++ b/Modules/posixmodule.c Thu Jun 02 16:58:00 2016 -0700 @@ -11718,6 +11718,13 @@ return PyUnicode_FromFormat("", self->name); } +static PyObject * +DirEntry_fspath(DirEntry * self) +{ + Py_INCREF(self->path); + return self->path; +} + static PyMemberDef DirEntry_members[] = { {"name", T_OBJECT_EX, offsetof(DirEntry, name), READONLY, "the entry's base filename, relative to scandir() \"path\" argument"}, @@ -11742,6 +11749,9 @@ {"inode", (PyCFunction)DirEntry_inode, METH_NOARGS, "return inode of the entry; cached per entry", }, + {"__fspath__", (PyCFunction)DirEntry_fspath, METH_NOARGS, + "returns the path for the entry", + }, {NULL} };