Skip to content

bpo-42999: expand and clarify pathlib.Path.link_to() documentation. #24294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions Doc/library/pathlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,20 @@ call fails (for example because the path doesn't exist).
of :func:`os.symlink`'s.


.. method:: Path.link_to(target)

Make *target* a hard link to this path.

.. warning::

This function does not make this path a hard link to *target*, despite
the implication of the function and argument names. The argument order
(target, link) is the reverse of :func:`Path.symlink_to`, but matches
that of :func:`os.link`.

.. versionadded:: 3.8


.. method:: Path.touch(mode=0o666, exist_ok=True)

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


.. method:: Path.link_to(target)

Create a hard link pointing to a path named *target*.

.. versionadded:: 3.8


.. method:: Path.write_bytes(data)

Open the file pointed to in bytes mode, write *data* to it, and close the
Expand Down
22 changes: 14 additions & 8 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1323,12 +1323,6 @@ def lstat(self):
"""
return self._accessor.lstat(self)

def link_to(self, target):
"""
Create a hard link pointing to a path named target.
"""
self._accessor.link(self, target)

def rename(self, target):
"""
Rename this path to the target path.
Expand Down Expand Up @@ -1357,11 +1351,23 @@ def replace(self, target):

def symlink_to(self, target, target_is_directory=False):
"""
Make this path a symlink pointing to the given path.
Note the order of arguments (self, target) is the reverse of os.symlink's.
Make this path a symlink pointing to the target path.
Note the order of arguments (link, target) is the reverse of os.symlink.
"""
self._accessor.symlink(target, self, target_is_directory)

def link_to(self, target):
"""
Make the target path a hard link pointing to this path.

Note this function does not make this path a hard link to *target*,
despite the implication of the function and argument names. The order
of arguments (target, link) is the reverse of Path.symlink_to, but
matches that of os.link.

"""
self._accessor.link(self, target)

# Convenience functions for querying the stat results

def exists(self):
Expand Down