Skip to content

Commit 9f57873

Browse files
zoobabarneygale
andauthored
bpo-42999: Expand and clarify pathlib.Path.link_to() documentation. (GH-24294)
Co-authored-by: Barney Gale <barney.gale@gmail.com>
1 parent d0e858d commit 9f57873

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

Doc/library/pathlib.rst

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

10651065

1066+
.. method:: Path.link_to(target)
1067+
1068+
Make *target* a hard link to this path.
1069+
1070+
.. warning::
1071+
1072+
This function does not make this path a hard link to *target*, despite
1073+
the implication of the function and argument names. The argument order
1074+
(target, link) is the reverse of :func:`Path.symlink_to`, but matches
1075+
that of :func:`os.link`.
1076+
1077+
.. versionadded:: 3.8
1078+
1079+
10661080
.. method:: Path.touch(mode=0o666, exist_ok=True)
10671081

10681082
Create a file at this given path. If *mode* is given, it is combined
@@ -1087,13 +1101,6 @@ call fails (for example because the path doesn't exist).
10871101
The *missing_ok* parameter was added.
10881102

10891103

1090-
.. method:: Path.link_to(target)
1091-
1092-
Create a hard link pointing to a path named *target*.
1093-
1094-
.. versionadded:: 3.8
1095-
1096-
10971104
.. method:: Path.write_bytes(data)
10981105

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

Lib/pathlib.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,14 +1343,6 @@ def lstat(self):
13431343
self._raise_closed()
13441344
return self._accessor.lstat(self)
13451345

1346-
def link_to(self, target):
1347-
"""
1348-
Create a hard link pointing to a path named target.
1349-
"""
1350-
if self._closed:
1351-
self._raise_closed()
1352-
self._accessor.link_to(self, target)
1353-
13541346
def rename(self, target):
13551347
"""
13561348
Rename this path to the target path.
@@ -1383,13 +1375,27 @@ def replace(self, target):
13831375

13841376
def symlink_to(self, target, target_is_directory=False):
13851377
"""
1386-
Make this path a symlink pointing to the given path.
1387-
Note the order of arguments (self, target) is the reverse of os.symlink's.
1378+
Make this path a symlink pointing to the target path.
1379+
Note the order of arguments (link, target) is the reverse of os.symlink.
13881380
"""
13891381
if self._closed:
13901382
self._raise_closed()
13911383
self._accessor.symlink(target, self, target_is_directory)
13921384

1385+
def link_to(self, target):
1386+
"""
1387+
Make the target path a hard link pointing to this path.
1388+
1389+
Note this function does not make this path a hard link to *target*,
1390+
despite the implication of the function and argument names. The order
1391+
of arguments (target, link) is the reverse of Path.symlink_to, but
1392+
matches that of os.link.
1393+
1394+
"""
1395+
if self._closed:
1396+
self._raise_closed()
1397+
self._accessor.link_to(self, target)
1398+
13931399
# Convenience functions for querying the stat results
13941400

13951401
def exists(self):

0 commit comments

Comments
 (0)