Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplify handling of missing os.readlink(), symlink() and link().
  • Loading branch information
barneygale committed Jan 1, 2022
commit d07f465bd94326a759e11ac8e1505eee273bf595
16 changes: 6 additions & 10 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,11 +1076,9 @@ def readlink(self):
"""
Return the path to which the symbolic link points.
"""
if hasattr(os, "readlink"):
path = os.readlink(self)
else:
if not hasattr(os, "readlink"):
raise NotImplementedError("os.readlink() not available on this system")
return self._from_parts((path,))
return self._from_parts((os.readlink(self),))

def touch(self, mode=0o666, exist_ok=True):
"""
Expand Down Expand Up @@ -1189,21 +1187,19 @@ def symlink_to(self, target, target_is_directory=False):
Make this path a symlink pointing to the target path.
Note the order of arguments (link, target) is the reverse of os.symlink.
"""
if hasattr(os, "symlink"):
os.symlink(target, self, target_is_directory)
else:
if not hasattr(os, "symlink"):
raise NotImplementedError("os.symlink() not available on this system")
os.symlink(target, self, target_is_directory)

def hardlink_to(self, target):
"""
Make this path a hard link pointing to the same file as *target*.

Note the order of arguments (self, target) is the reverse of os.link's.
"""
if hasattr(os, "link"):
os.link(target, self)
else:
if not hasattr(os, "link"):
raise NotImplementedError("os.link() not available on this system")
os.link(target, self)

def link_to(self, target):
"""
Expand Down