From 07b34926d3090e50f9ecaa213c564f98fc9a5a93 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Tue, 10 May 2022 12:31:41 -0700 Subject: gh-84131: Remove the deprecated pathlib.Path.link_to method. (#92505) Co-authored-by: Barney Gale --- Doc/library/pathlib.rst | 19 ----------------- Doc/whatsnew/3.8.rst | 3 +++ Lib/pathlib.py | 17 --------------- Lib/test/test_pathlib.py | 24 +--------------------- .../2022-05-08-19-21-14.gh-issue-84131.rG5kI7.rst | 3 +++ 5 files changed, 7 insertions(+), 59 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2022-05-08-19-21-14.gh-issue-84131.rG5kI7.rst diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index 01e9cfb..535b5ab 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 7c293a5..6b88cf6 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 4763ab5..be3fd01 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -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 diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py index b8b08bf..3412d84 100644 --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -1978,28 +1978,6 @@ class _BasePathTest(object): 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) target = P / 'fileA' @@ -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 index 0000000..4a930bd --- /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`. -- cgit v0.12