Skip to content

Commit 34f9300

Browse files
zoobabarneygale
andauthored
bpo-42999: Expand and clarify pathlib.Path.link_to() documentation. (GH-24294)
Co-authored-by: Barney Gale <[email protected]>
1 parent a21d4fb commit 34f9300

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
@@ -1119,6 +1119,20 @@ call fails (for example because the path doesn't exist).
11191119
of :func:`os.symlink`'s.
11201120

11211121

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

11241138
Create a file at this given path. If *mode* is given, it is combined
@@ -1143,13 +1157,6 @@ call fails (for example because the path doesn't exist).
11431157
The *missing_ok* parameter was added.
11441158

11451159

1146-
.. method:: Path.link_to(target)
1147-
1148-
Create a hard link pointing to a path named *target*.
1149-
1150-
.. versionadded:: 3.8
1151-
1152-
11531160
.. method:: Path.write_bytes(data)
11541161

11551162
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
@@ -1358,12 +1358,6 @@ def lstat(self):
13581358
"""
13591359
return self._accessor.lstat(self)
13601360

1361-
def link_to(self, target):
1362-
"""
1363-
Create a hard link pointing to a path named target.
1364-
"""
1365-
self._accessor.link_to(self, target)
1366-
13671361
def rename(self, target):
13681362
"""
13691363
Rename this path to the target path.
@@ -1392,11 +1386,23 @@ def replace(self, target):
13921386

13931387
def symlink_to(self, target, target_is_directory=False):
13941388
"""
1395-
Make this path a symlink pointing to the given path.
1396-
Note the order of arguments (self, target) is the reverse of os.symlink's.
1389+
Make this path a symlink pointing to the target path.
1390+
Note the order of arguments (link, target) is the reverse of os.symlink.
13971391
"""
13981392
self._accessor.symlink(target, self, target_is_directory)
13991393

1394+
def link_to(self, target):
1395+
"""
1396+
Make the target path a hard link pointing to this path.
1397+
1398+
Note this function does not make this path a hard link to *target*,
1399+
despite the implication of the function and argument names. The order
1400+
of arguments (target, link) is the reverse of Path.symlink_to, but
1401+
matches that of os.link.
1402+
1403+
"""
1404+
self._accessor.link_to(self, target)
1405+
14001406
# Convenience functions for querying the stat results
14011407

14021408
def exists(self):

0 commit comments

Comments
 (0)