Skip to content

Commit d07f465

Browse files
committed
Simplify handling of missing os.readlink(), symlink() and link().
1 parent 613a171 commit d07f465

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

Lib/pathlib.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -1076,11 +1076,9 @@ def readlink(self):
10761076
"""
10771077
Return the path to which the symbolic link points.
10781078
"""
1079-
if hasattr(os, "readlink"):
1080-
path = os.readlink(self)
1081-
else:
1079+
if not hasattr(os, "readlink"):
10821080
raise NotImplementedError("os.readlink() not available on this system")
1083-
return self._from_parts((path,))
1081+
return self._from_parts((os.readlink(self),))
10841082

10851083
def touch(self, mode=0o666, exist_ok=True):
10861084
"""
@@ -1189,21 +1187,19 @@ def symlink_to(self, target, target_is_directory=False):
11891187
Make this path a symlink pointing to the target path.
11901188
Note the order of arguments (link, target) is the reverse of os.symlink.
11911189
"""
1192-
if hasattr(os, "symlink"):
1193-
os.symlink(target, self, target_is_directory)
1194-
else:
1190+
if not hasattr(os, "symlink"):
11951191
raise NotImplementedError("os.symlink() not available on this system")
1192+
os.symlink(target, self, target_is_directory)
11961193

11971194
def hardlink_to(self, target):
11981195
"""
11991196
Make this path a hard link pointing to the same file as *target*.
12001197
12011198
Note the order of arguments (self, target) is the reverse of os.link's.
12021199
"""
1203-
if hasattr(os, "link"):
1204-
os.link(target, self)
1205-
else:
1200+
if not hasattr(os, "link"):
12061201
raise NotImplementedError("os.link() not available on this system")
1202+
os.link(target, self)
12071203

12081204
def link_to(self, target):
12091205
"""

0 commit comments

Comments
 (0)