Skip to content

Commit 8aac1be

Browse files
authored
bpo-42999: Expand and clarify pathlib.Path.link_to() documentation. (GH-24294)
1 parent abf9649 commit 8aac1be

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

11361136

1137+
.. method:: Path.link_to(target)
1138+
1139+
Make *target* a hard link to this path.
1140+
1141+
.. warning::
1142+
1143+
This function does not make this path a hard link to *target*, despite
1144+
the implication of the function and argument names. The argument order
1145+
(target, link) is the reverse of :func:`Path.symlink_to`, but matches
1146+
that of :func:`os.link`.
1147+
1148+
.. versionadded:: 3.8
1149+
1150+
11371151
.. method:: Path.touch(mode=0o666, exist_ok=True)
11381152

11391153
Create a file at this given path. If *mode* is given, it is combined
@@ -1158,13 +1172,6 @@ call fails (for example because the path doesn't exist).
11581172
The *missing_ok* parameter was added.
11591173

11601174

1161-
.. method:: Path.link_to(target)
1162-
1163-
Create a hard link pointing to a path named *target*.
1164-
1165-
.. versionadded:: 3.8
1166-
1167-
11681175
.. method:: Path.write_bytes(data)
11691176

11701177
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
@@ -1315,12 +1315,6 @@ def lstat(self):
13151315
"""
13161316
return self.stat(follow_symlinks=False)
13171317

1318-
def link_to(self, target):
1319-
"""
1320-
Create a hard link pointing to a path named target.
1321-
"""
1322-
self._accessor.link(self, target)
1323-
13241318
def rename(self, target):
13251319
"""
13261320
Rename this path to the target path.
@@ -1349,11 +1343,23 @@ def replace(self, target):
13491343

13501344
def symlink_to(self, target, target_is_directory=False):
13511345
"""
1352-
Make this path a symlink pointing to the given path.
1353-
Note the order of arguments (self, target) is the reverse of os.symlink's.
1346+
Make this path a symlink pointing to the target path.
1347+
Note the order of arguments (link, target) is the reverse of os.symlink.
13541348
"""
13551349
self._accessor.symlink(target, self, target_is_directory)
13561350

1351+
def link_to(self, target):
1352+
"""
1353+
Make the target path a hard link pointing to this path.
1354+
1355+
Note this function does not make this path a hard link to *target*,
1356+
despite the implication of the function and argument names. The order
1357+
of arguments (target, link) is the reverse of Path.symlink_to, but
1358+
matches that of os.link.
1359+
1360+
"""
1361+
self._accessor.link(self, target)
1362+
13571363
# Convenience functions for querying the stat results
13581364

13591365
def exists(self):

0 commit comments

Comments
 (0)