]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-84131: Remove the deprecated pathlib.Path.link_to method. (#92505)
authorGregory P. Smith <greg@krypto.org>
Tue, 10 May 2022 19:31:41 +0000 (12:31 -0700)
committerGitHub <noreply@github.com>
Tue, 10 May 2022 19:31:41 +0000 (12:31 -0700)
Co-authored-by: Barney Gale <barney.gale@gmail.com>
Doc/library/pathlib.rst
Doc/whatsnew/3.8.rst
Lib/pathlib.py
Lib/test/test_pathlib.py
Misc/NEWS.d/next/Library/2022-05-08-19-21-14.gh-issue-84131.rG5kI7.rst [new file with mode: 0644]

index 01e9cfb93e391127d8881a02f277b7191242ec82..535b5abf8e3ff8673809a2e18effa2111190502b 100644 (file)
@@ -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)
 
index 7c293a501895b367847967d3baabd1eed742d656..6b88cf66069198c9476f4f555e7e69c4d1d91321 100644 (file)
@@ -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
index 4763ab54f6ba81f21eb0a43d7719bb46a68cf2ce..be3fd011795e590a6896250103bcbb7e4c77a391 100644 (file)
@@ -1199,23 +1199,6 @@ class Path(PurePath):
             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
 
index b8b08bf0ce1bb598596da814e643263f7dba6060..3412d8431ab853c261e568907c1c9a97c861349a 100644 (file)
@@ -1977,28 +1977,6 @@ class _BasePathTest(object):
         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 @@ class _BasePathTest(object):
         # 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 (file)
index 0000000..4a930bd
--- /dev/null
@@ -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`.