mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
gh-84131: Remove the deprecated pathlib.Path.link_to method. (#92505)
Co-authored-by: Barney Gale <barney.gale@gmail.com>
This commit is contained in:
parent
dde8a1668e
commit
07b34926d3
5 changed files with 7 additions and 59 deletions
|
@ -1162,25 +1162,6 @@ call fails (for example because the path doesn't exist).
|
||||||
|
|
||||||
.. versionadded:: 3.10
|
.. 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)
|
.. method:: Path.touch(mode=0o666, exist_ok=True)
|
||||||
|
|
||||||
|
|
|
@ -1087,6 +1087,9 @@ contain characters unrepresentable at the OS level.
|
||||||
Added :meth:`pathlib.Path.link_to()` which creates a hard link pointing
|
Added :meth:`pathlib.Path.link_to()` which creates a hard link pointing
|
||||||
to a path.
|
to a path.
|
||||||
(Contributed by Joannah Nanjekye in :issue:`26978`)
|
(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
|
pickle
|
||||||
|
|
|
@ -1199,23 +1199,6 @@ class Path(PurePath):
|
||||||
raise NotImplementedError("os.link() not available on this system")
|
raise NotImplementedError("os.link() not available on this system")
|
||||||
os.link(target, self)
|
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
|
# Convenience functions for querying the stat results
|
||||||
|
|
||||||
|
|
|
@ -1977,28 +1977,6 @@ class _BasePathTest(object):
|
||||||
self.assertFileNotFound(p.stat)
|
self.assertFileNotFound(p.stat)
|
||||||
self.assertFileNotFound(p.unlink)
|
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")
|
@unittest.skipUnless(hasattr(os, "link"), "os.link() is not present")
|
||||||
def test_hardlink_to(self):
|
def test_hardlink_to(self):
|
||||||
P = self.cls(BASE)
|
P = self.cls(BASE)
|
||||||
|
@ -2024,7 +2002,7 @@ class _BasePathTest(object):
|
||||||
# linking to another path.
|
# linking to another path.
|
||||||
q = P / 'dirA' / 'fileAA'
|
q = P / 'dirA' / 'fileAA'
|
||||||
with self.assertRaises(NotImplementedError):
|
with self.assertRaises(NotImplementedError):
|
||||||
p.link_to(q)
|
q.hardlink_to(p)
|
||||||
|
|
||||||
def test_rename(self):
|
def test_rename(self):
|
||||||
P = self.cls(BASE)
|
P = self.cls(BASE)
|
||||||
|
|
|
@ -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`.
|
Loading…
Add table
Add a link
Reference in a new issue