diff options
author | Barney Gale <barney.gale@gmail.com> | 2021-04-23 20:48:52 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-23 20:48:52 (GMT) |
commit | f24e2e5464ba6498e7b8d73c3f9b417d59fd1b26 (patch) | |
tree | cef5b64a2c1c204cc45ec778be4689f0ed5d811d /Doc | |
parent | e047239eafefe8b19725efffe7756443495cf78b (diff) | |
download | cpython-f24e2e5464ba6498e7b8d73c3f9b417d59fd1b26.zip cpython-f24e2e5464ba6498e7b8d73c3f9b417d59fd1b26.tar.gz cpython-f24e2e5464ba6498e7b8d73c3f9b417d59fd1b26.tar.bz2 |
bpo-39950: add `pathlib.Path.hardlink_to()` method that supersedes `link_to()` (GH-18909)
The argument order of `link_to()` is reversed compared to what one may expect, so:
a.link_to(b)
Might be expected to create *a* as a link to *b*, in fact it creates *b* as a link to *a*, making it function more like a "link from". This doesn't match `symlink_to()` nor the documentation and doesn't seem to be the original author's intent.
This PR deprecates `link_to()` and introduces `hardlink_to()`, which has the same argument order as `symlink_to()`.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/pathlib.rst | 21 | ||||
-rw-r--r-- | Doc/whatsnew/3.10.rst | 9 |
2 files changed, 27 insertions, 3 deletions
diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index 122642a..b6507eb 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -1140,6 +1140,15 @@ call fails (for example because the path doesn't exist). The order of arguments (link, target) is the reverse of :func:`os.symlink`'s. +.. method:: Path.hardlink_to(target) + + Make this path a hard link to the same file as *target*. + + .. note:: + The order of arguments (link, target) is the reverse + of :func:`os.link`'s. + + .. versionadded:: 3.10 .. method:: Path.link_to(target) @@ -1149,11 +1158,17 @@ call fails (for example because the path doesn't exist). 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`. + (target, link) is the reverse of :func:`Path.symlink_to` and + :func:`Path.hardlink_to`, but matches that of :func:`os.link`. .. versionadded:: 3.8 + .. deprecated:: 3.10 + + This method is deprecated in favor of :meth:`Path.hardlink_to`, as the + argument order of :meth:`Path.link_to` does not match that of + :meth:`Path.symlink_to`. + .. method:: Path.touch(mode=0o666, exist_ok=True) @@ -1246,7 +1261,7 @@ Below is a table mapping various :mod:`os` functions to their corresponding :func:`os.path.isdir` :meth:`Path.is_dir` :func:`os.path.isfile` :meth:`Path.is_file` :func:`os.path.islink` :meth:`Path.is_symlink` -:func:`os.link` :meth:`Path.link_to` +:func:`os.link` :meth:`Path.hardlink_to` :func:`os.symlink` :meth:`Path.symlink_to` :func:`os.readlink` :meth:`Path.readlink` :func:`os.path.relpath` :meth:`Path.relative_to` [#]_ diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst index 86cf11f..247749a 100644 --- a/Doc/whatsnew/3.10.rst +++ b/Doc/whatsnew/3.10.rst @@ -1007,6 +1007,11 @@ Added negative indexing support to :attr:`PurePath.parents <pathlib.PurePath.parents>`. (Contributed by Yaroslav Pankovych in :issue:`21041`) +Added :meth:`Path.hardlink_to <pathlib.Path.hardlink_to>` method that +supersedes :meth:`~pathlib.Path.link_to`. The new method has the same argument +order as :meth:`~pathlib.Path.symlink_to`. +(Contributed by Barney Gale in :issue:`39950`.) + platform -------- @@ -1363,6 +1368,10 @@ Deprecated (Contributed by Jelle Zijlstra in :issue:`21574`.) +* :meth:`pathlib.Path.link_to` is deprecated and slated for removal in + Python 3.12. Use :meth:`pathlib.Path.hardlink_to` instead. + (Contributed by Barney Gale in :issue:`39950`.) + Removed ======= |