Skip to content

Commit f7640fd

Browse files
committed
bpo-42999: expand and clarify pathlib.Path.link_to() documentation.
1 parent 2219187 commit f7640fd

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

Doc/library/pathlib.rst

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,20 @@ call fails (for example because the path doesn't exist).
11211121
of :func:`os.symlink`'s.
11221122

11231123

1124+
.. method:: Path.link_to(target)
1125+
1126+
Make *target* a hard link to this path.
1127+
1128+
.. warning::
1129+
1130+
This function does not make this path a hard link to *target*, despite
1131+
the implication of the function and argument names. The argument order
1132+
(target, link) is the reverse of :func:`Path.symlink_to`, but matches
1133+
that of :func:`os.link`.
1134+
1135+
.. versionadded:: 3.8
1136+
1137+
11241138
.. method:: Path.touch(mode=0o666, exist_ok=True)
11251139

11261140
Create a file at this given path. If *mode* is given, it is combined
@@ -1145,13 +1159,6 @@ call fails (for example because the path doesn't exist).
11451159
The *missing_ok* parameter was added.
11461160

11471161

1148-
.. method:: Path.link_to(target)
1149-
1150-
Create a hard link pointing to a path named *target*.
1151-
1152-
.. versionadded:: 3.8
1153-
1154-
11551162
.. method:: Path.write_bytes(data)
11561163

11571164
Open the file pointed to in bytes mode, write *data* to it, and close the

Lib/pathlib.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,12 +1323,6 @@ def lstat(self):
13231323
"""
13241324
return self._accessor.lstat(self)
13251325

1326-
def link_to(self, target):
1327-
"""
1328-
Create a hard link pointing to a path named target.
1329-
"""
1330-
self._accessor.link(self, target)
1331-
13321326
def rename(self, target):
13331327
"""
13341328
Rename this path to the target path.
@@ -1357,11 +1351,23 @@ def replace(self, target):
13571351

13581352
def symlink_to(self, target, target_is_directory=False):
13591353
"""
1360-
Make this path a symlink pointing to the given path.
1361-
Note the order of arguments (self, target) is the reverse of os.symlink's.
1354+
Make this path a symlink pointing to the target path.
1355+
Note the order of arguments (link, target) is the reverse of os.symlink.
13621356
"""
13631357
self._accessor.symlink(target, self, target_is_directory)
13641358

1359+
def link_to(self, target):
1360+
"""
1361+
Make the target path a hard link pointing to this path.
1362+
1363+
Note this function does not make this path a hard link to *target*,
1364+
despite the implication of the function and argument names. The order
1365+
of arguments (target, link) is the reverse of Path.symlink_to, but
1366+
matches that of os.link.
1367+
1368+
"""
1369+
self._accessor.link(self, target)
1370+
13651371
# Convenience functions for querying the stat results
13661372

13671373
def exists(self):

0 commit comments

Comments
 (0)