diff -r 14ff7b1383a7 Doc/library/pathlib.rst --- a/Doc/library/pathlib.rst Thu Dec 05 07:53:38 2013 +0100 +++ b/Doc/library/pathlib.rst Thu Dec 05 10:22:26 2013 +0200 @@ -883,3 +883,13 @@ Remove this file or symbolic link. If the path points to a directory, use :func:`Path.rmdir` instead. + +.. method:: Path.expanduser() + + Return a new :class:`Path` with expanded ``~`` and ``~user`` constructs, + as returned by :meth:`os.path.expanduser`. + + >>> p = PosixPath('~root') + >>> p.expanduser() + PosixPath('/root') + diff -r 14ff7b1383a7 Lib/pathlib.py --- a/Lib/pathlib.py Thu Dec 05 07:53:38 2013 +0100 +++ b/Lib/pathlib.py Thu Dec 05 10:22:26 2013 +0200 @@ -950,6 +950,12 @@ """ return cls(os.getcwd()) + def expanduser(self): + """ Return a new path with expanded ~ and ~user constructs + (as returned by os.path.expanduser) + """ + return self.__class__(os.path.expanduser(str(self))) + def iterdir(self): """Iterate over the files in this directory. Does not yield any result for the special paths '.' and '..'. diff -r 14ff7b1383a7 Lib/test/test_pathlib.py --- a/Lib/test/test_pathlib.py Thu Dec 05 07:53:38 2013 +0100 +++ b/Lib/test/test_pathlib.py Thu Dec 05 10:22:26 2013 +0200 @@ -1135,6 +1135,11 @@ p = self.cls('') self.assertEqual(p.stat(), os.stat('.')) + def test_expanduser(self): + p = self.cls('~') + self.assertEqual(os.path.expanduser(str(p)), + str(p.expanduser())) + def test_exists(self): P = self.cls p = P(BASE)