This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add pathlib.Path.hardlink_to()
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: barneygale, escape0707, gregory.p.smith, miss-islington, xtreak
Priority: normal Keywords: patch

Created on 2020-03-13 00:50 by barneygale, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 18909 merged barneygale, 2020-03-13 00:50
PR 26155 merged barneygale, 2021-05-15 22:32
PR 26158 closed miss-islington, 2021-05-16 07:15
PR 26178 merged miss-islington, 2021-05-16 22:07
Messages (9)
msg364060 - (view) Author: Barney Gale (barneygale) * Date: 2020-03-13 00:50
Per bpo-39291, the argument order for `pathlib.Path.link_to()` is inconsistent with `symlink_to()` and its own documentation.

This ticket covers adding a new `hardlink_to()` method with the correct argument order, and deprecating `link_to()`.

Discussion on python-dev: https://mail.python.org/archives/list/python-dev@python.org/thread/7QPLYW36ZK6QTW4SV4FI6C343KYWCPAT/
msg365275 - (view) Author: Barney Gale (barneygale) * Date: 2020-03-29 19:52
A question:

For my patch, I need to include a Python version where `Path.link_to()` will become unavailable. I'm not entirely sure how this should be determined. Some factors in play:

- `link_to()` was added in Python 3.8
- On github, I found these three repos which use `link_to()`:
  - https://github.com/akubera/pion-analysis
  - https://github.com/DailyDreaming/load-project
  - https://github.com/eight04/vpip

Can anyone suggest in which version of Python this function should be removed? Thanks.
msg385199 - (view) Author: Jay Chu (escape0707) Date: 2021-01-18 14:42
Maybe we could have the correct `Path.hardlink` implemented before removing or even deprecating the confusing `Path.link_to`? It will only help even if we don't remove the latter in a hurry.
msg385458 - (view) Author: Barney Gale (barneygale) * Date: 2021-01-21 23:56
Makes sense to me. Should I leave the documentation for `link_to` completely alone? With the addition of a similar function, I wonder if that may in itself cause confusion.
msg385471 - (view) Author: Jay Chu (escape0707) Date: 2021-01-22 03:40
For me, and as you've pointed out, the current doc of `Path.link_to` is already wrong and misleading. Perhaps a fix of the doc should be made as a first step.

The doc uses the expression "Create a hard link pointing to a path named target." 
But comparing this to the doc of `Path.symlink_to`, which says "Make this path a symbolic link to target.", 
(and the doc of `os.link`, which says, "Create a hard link pointing to src named dst.",)
the current doc should actually be "Create a hard link at `target` pointing to this path." Sadly the argument name can't be changed here already.

And the doc of `Path.symlink_to` even have a helpful note: "Note: The order of arguments (link, target) is the reverse of os.symlink()’s." 
We could also add one for `Path.link_to`, too, like "Note: The order of arguments (link, target) is the consistent with os.link()’s.

Based on that foundation, we could finally continue to implement the correct "Path.hardlink_to". 

We can refer to how people retained `subprocess.call` while adding a newer , preferred `subprocess.run`, by noting people to prefer `Path.hardlink_to` as it's more consistent with the `pathlib` and OOP, along with telling them the obscurity of `Path.link_to` and why it's left here for backward capability.
msg385475 - (view) Author: Barney Gale (barneygale) * Date: 2021-01-22 04:26
I've logged bpo-42999 to cover fixing the existing `link_to()` docs issues. PR incoming...
msg391734 - (view) Author: miss-islington (miss-islington) Date: 2021-04-23 20:48
New changeset f24e2e5464ba6498e7b8d73c3f9b417d59fd1b26 by Barney Gale in branch 'master':
bpo-39950: add `pathlib.Path.hardlink_to()` method that supersedes `link_to()` (GH-18909)
https://github.com/python/cpython/commit/f24e2e5464ba6498e7b8d73c3f9b417d59fd1b26
msg392779 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2021-05-03 08:12
The changes have introduced deprecation warnings in tests. It seems https://github.com/python/cpython/blob/ad106c68eb00f5e4af2f937107baff6141948cee/Lib/test/test_pathlib.py#L1937 is not covered.

./python -Wall -m test test_pathlib                      
0:00:00 load avg: 0.81 Run tests sequentially
0:00:00 load avg: 0.81 [1/1] test_pathlib
/root/cpython/Lib/pathlib.py:1265: DeprecationWarning: pathlib.Path.link_to() is deprecated and is scheduled for removal in Python 3.12. Use pathlib.Path.hardlink_to() instead.
  warnings.warn("pathlib.Path.link_to() is deprecated and is scheduled "
/root/cpython/Lib/pathlib.py:1265: DeprecationWarning: pathlib.Path.link_to() is deprecated and is scheduled for removal in Python 3.12. Use pathlib.Path.hardlink_to() instead.
  warnings.warn("pathlib.Path.link_to() is deprecated and is scheduled "

== Tests result: SUCCESS ==

1 test OK.

Total duration: 2.9 sec
Tests result: SUCCESS

Also it will be nice to point to the line causing deprecation instead of the library soruce code that will help users identify the deprecated usage. Using stacklevel=2 might help here https://docs.python.org/3/library/warnings.html#warnings.warn


./python -Wall -m test test_pathlib  
0:00:00 load avg: 1.82 Run tests sequentially
0:00:00 load avg: 1.82 [1/1] test_pathlib
/root/cpython/Lib/test/test_pathlib.py:1937: DeprecationWarning: pathlib.Path.link_to() is deprecated and is scheduled for removal in Python 3.12. Use pathlib.Path.hardlink_to() instead.
  q.link_to(r)
/root/cpython/Lib/test/test_pathlib.py:1937: DeprecationWarning: pathlib.Path.link_to() is deprecated and is scheduled for removal in Python 3.12. Use pathlib.Path.hardlink_to() instead.
  q.link_to(r)

== Tests result: SUCCESS ==

1 test OK.

Total duration: 4.3 sec
Tests result: SUCCESS
msg393765 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2021-05-16 22:35
New changeset b913f47e87f788e705716ae037ee9f68b4265e69 by Miss Islington (bot) in branch '3.10':
bpo-39950: Fix deprecation warning in test for `pathlib.Path.link_to()` (GH-26155) (GH-26178)
https://github.com/python/cpython/commit/b913f47e87f788e705716ae037ee9f68b4265e69
History
Date User Action Args
2022-04-11 14:59:28adminsetgithub: 84131
2021-06-13 15:49:54barneygalesetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
versions: + Python 3.10, - Python 3.9
2021-05-16 22:35:52gregory.p.smithsetnosy: + gregory.p.smith
messages: + msg393765
2021-05-16 22:07:20miss-islingtonsetpull_requests: + pull_request24801
2021-05-16 07:15:39miss-islingtonsetpull_requests: + pull_request24792
2021-05-15 22:32:47barneygalesetstage: resolved -> patch review
pull_requests: + pull_request24789
2021-05-15 22:27:29barneygalesetstatus: closed -> open
resolution: fixed -> (no value)
2021-05-15 22:25:08barneygalesetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-05-03 08:12:53xtreaksetnosy: + xtreak
messages: + msg392779
2021-04-23 20:48:59miss-islingtonsetnosy: + miss-islington
messages: + msg391734
2021-01-22 04:26:32barneygalesetmessages: + msg385475
2021-01-22 03:40:31escape0707setmessages: + msg385471
2021-01-21 23:56:50barneygalesetmessages: + msg385458
2021-01-18 14:42:44escape0707setnosy: + escape0707
messages: + msg385199
2020-03-29 19:52:43barneygalesetmessages: + msg365275
2020-03-13 00:50:57barneygalesetkeywords: + patch
stage: patch review
pull_requests: + pull_request18321
2020-03-13 00:50:05barneygalecreate