[Python-checkins] gh-84131: Remove the deprecated pathlib.Path.link_to method. (#92505)

gpshead webhook-mailer at python.org
Tue May 10 15:31:53 EDT 2022


https://github.com/python/cpython/commit/07b34926d3090e50f9ecaa213c564f98fc9a5a93
commit: 07b34926d3090e50f9ecaa213c564f98fc9a5a93
branch: main
author: Gregory P. Smith <greg at krypto.org>
committer: gpshead <greg at krypto.org>
date: 2022-05-10T12:31:41-07:00
summary:

gh-84131: Remove the deprecated pathlib.Path.link_to method. (#92505)


Co-authored-by: Barney Gale <barney.gale at gmail.com>

files:
A Misc/NEWS.d/next/Library/2022-05-08-19-21-14.gh-issue-84131.rG5kI7.rst
M Doc/library/pathlib.rst
M Doc/whatsnew/3.8.rst
M Lib/pathlib.py
M Lib/test/test_pathlib.py

diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst
index 01e9cfb93e391..535b5abf8e3ff 100644
--- a/Doc/library/pathlib.rst
+++ b/Doc/library/pathlib.rst
@@ -1162,25 +1162,6 @@ call fails (for example because the path doesn't exist).
 
    .. versionadded:: 3.10
 
-.. 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` 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)
 
diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst
index 7c293a501895b..6b88cf6606919 100644
--- a/Doc/whatsnew/3.8.rst
+++ b/Doc/whatsnew/3.8.rst
@@ -1087,6 +1087,9 @@ contain characters unrepresentable at the OS level.
 Added :meth:`pathlib.Path.link_to()` which creates a hard link pointing
 to a path.
 (Contributed by Joannah Nanjekye in :issue:`26978`)
+Note that ``link_to`` was deprecated in 3.10 and removed in 3.12 in
+favor of a ``hardlink_to`` method added in 3.10 which matches the
+semantics of the existing ``symlink_to`` method.
 
 
 pickle
diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index 4763ab54f6ba8..be3fd011795e5 100644
--- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -1199,23 +1199,6 @@ def hardlink_to(self, target):
             raise NotImplementedError("os.link() not available on this system")
         os.link(target, self)
 
-    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.
-
-        Deprecated since Python 3.10 and scheduled for removal in Python 3.12.
-        Use `hardlink_to()` instead.
-        """
-        warnings.warn("pathlib.Path.link_to() is deprecated and is scheduled "
-                      "for removal in Python 3.12. "
-                      "Use pathlib.Path.hardlink_to() instead.",
-                      DeprecationWarning, stacklevel=2)
-        self.__class__(target).hardlink_to(self)
 
     # Convenience functions for querying the stat results
 
diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py
index b8b08bf0ce1bb..3412d8431ab85 100644
--- a/Lib/test/test_pathlib.py
+++ b/Lib/test/test_pathlib.py
@@ -1977,28 +1977,6 @@ def test_rmdir(self):
         self.assertFileNotFound(p.stat)
         self.assertFileNotFound(p.unlink)
 
-    @unittest.skipUnless(hasattr(os, "link"), "os.link() is not present")
-    def test_link_to(self):
-        P = self.cls(BASE)
-        p = P / 'fileA'
-        size = p.stat().st_size
-        # linking to another path.
-        q = P / 'dirA' / 'fileAA'
-        try:
-            with self.assertWarns(DeprecationWarning):
-                p.link_to(q)
-        except PermissionError as e:
-            self.skipTest('os.link(): %s' % e)
-        self.assertEqual(q.stat().st_size, size)
-        self.assertEqual(os.path.samefile(p, q), True)
-        self.assertTrue(p.stat)
-        # Linking to a str of a relative path.
-        r = rel_join('fileAAA')
-        with self.assertWarns(DeprecationWarning):
-            q.link_to(r)
-        self.assertEqual(os.stat(r).st_size, size)
-        self.assertTrue(q.stat)
-
     @unittest.skipUnless(hasattr(os, "link"), "os.link() is not present")
     def test_hardlink_to(self):
         P = self.cls(BASE)
@@ -2024,7 +2002,7 @@ def test_link_to_not_implemented(self):
         # linking to another path.
         q = P / 'dirA' / 'fileAA'
         with self.assertRaises(NotImplementedError):
-            p.link_to(q)
+            q.hardlink_to(p)
 
     def test_rename(self):
         P = self.cls(BASE)
diff --git a/Misc/NEWS.d/next/Library/2022-05-08-19-21-14.gh-issue-84131.rG5kI7.rst b/Misc/NEWS.d/next/Library/2022-05-08-19-21-14.gh-issue-84131.rG5kI7.rst
new file mode 100644
index 0000000000000..4a930bde01153
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-05-08-19-21-14.gh-issue-84131.rG5kI7.rst
@@ -0,0 +1,3 @@
+The :class:`pathlib.Path` deprecated method ``link_to`` has been removed.
+Use 3.10's :meth:`~pathlib.Path.hardlink_to` method instead as its semantics
+are consistent with that of :meth:`~pathlib.Path.symlink_to`.



More information about the Python-checkins mailing list