bpo-30618: add readlink to pathlib.Path (GH-8285)

This adds a "readlink" method to pathlib.Path objects that calls through
to os.readlink.


https://bugs.python.org/issue30618



Automerge-Triggered-By: @gpshead
This commit is contained in:
Girts 2019-10-23 14:18:40 -07:00 committed by Miss Skeleton (bot)
parent 01659ca62c
commit a01ba333af
5 changed files with 41 additions and 0 deletions

View file

@ -1244,6 +1244,15 @@ class Path(PurePath):
with self.open(mode='w', encoding=encoding, errors=errors) as f:
return f.write(data)
def readlink(self):
"""
Return the path to which the symbolic link points.
"""
path = self._accessor.readlink(self)
obj = self._from_parts((path,), init=False)
obj._init(template=self)
return obj
def touch(self, mode=0o666, exist_ok=True):
"""
Create this file with the given access mode, if it doesn't exist.