https://github.com/python/cpython/commit/f772d0d08af2beef53db1e076c864cbdf3f5bac9
commit: f772d0d08af2beef53db1e076c864cbdf3f5bac9
branch: main
author: Barney Gale <[email protected]>
committer: barneygale <[email protected]>
date: 2024-05-10T15:53:46Z
summary:
GH-78707: Drop deprecated `pathlib.PurePath.[is_]relative_to()` arguments
(#118780)
Remove support for supplying additional positional arguments to
`PurePath.relative_to()` and `is_relative_to()`. This has been deprecated
since Python 3.12.
files:
A Misc/NEWS.d/next/Library/2024-05-08-18-59-19.gh-issue-78707._Lz1sw.rst
M Doc/whatsnew/3.14.rst
M Lib/pathlib/_local.py
M Lib/test/test_pathlib/test_pathlib.py
diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst
index 25c43dc0387eaf..52a24d1a9295a3 100644
--- a/Doc/whatsnew/3.14.rst
+++ b/Doc/whatsnew/3.14.rst
@@ -114,6 +114,14 @@ email
* The *isdst* parameter has been removed from :func:`email.utils.localtime`.
(Contributed by Hugo van Kemenade in :gh:`118798`.)
+pathlib
+-------
+
+* Remove support for passing additional positional arguments to
+ :meth:`pathlib.PurePath.relative_to` and
+ :meth:`~pathlib.PurePath.is_relative_to`. In previous versions, any such
+ arguments are joined onto *other*.
+
Others
------
diff --git a/Lib/pathlib/_local.py b/Lib/pathlib/_local.py
index b1e678aceb9ce8..f2c627319d520f 100644
--- a/Lib/pathlib/_local.py
+++ b/Lib/pathlib/_local.py
@@ -362,7 +362,7 @@ def with_name(self, name):
tail[-1] = name
return self._from_parsed_parts(self.drive, self.root, tail)
- def relative_to(self, other, /, *_deprecated, walk_up=False):
+ def relative_to(self, other, *, walk_up=False):
"""Return the relative path to another path identified by the passed
arguments. If the operation is not possible (because this is not
related to the other path), raise ValueError.
@@ -370,13 +370,7 @@ def relative_to(self, other, /, *_deprecated,
walk_up=False):
The *walk_up* parameter controls whether `..` may be used to resolve
the path.
"""
- if _deprecated:
- msg = ("support for supplying more than one positional argument "
- "to pathlib.PurePath.relative_to() is deprecated and "
- "scheduled for removal in Python 3.14")
- warnings.warn(msg, DeprecationWarning, stacklevel=2)
- other = self.with_segments(other, *_deprecated)
- elif not isinstance(other, PurePath):
+ if not isinstance(other, PurePath):
other = self.with_segments(other)
for step, path in enumerate(chain([other], other.parents)):
if path == self or path in self.parents:
@@ -390,16 +384,10 @@ def relative_to(self, other, /, *_deprecated,
walk_up=False):
parts = ['..'] * step + self._tail[len(path._tail):]
return self._from_parsed_parts('', '', parts)
- def is_relative_to(self, other, /, *_deprecated):
+ def is_relative_to(self, other):
"""Return True if the path is relative to another path or False.
"""
- if _deprecated:
- msg = ("support for supplying more than one argument to "
- "pathlib.PurePath.is_relative_to() is deprecated and "
- "scheduled for removal in Python 3.14")
- warnings.warn(msg, DeprecationWarning, stacklevel=2)
- other = self.with_segments(other, *_deprecated)
- elif not isinstance(other, PurePath):
+ if not isinstance(other, PurePath):
other = self.with_segments(other)
return other == self or other in self.parents
diff --git a/Lib/test/test_pathlib/test_pathlib.py
b/Lib/test/test_pathlib/test_pathlib.py
index 5fd1a41cbee17b..4fd2aac4a62139 100644
--- a/Lib/test/test_pathlib/test_pathlib.py
+++ b/Lib/test/test_pathlib/test_pathlib.py
@@ -311,19 +311,6 @@ def test_with_stem_empty(self):
self.assertRaises(ValueError, P('a/b').with_stem, '')
self.assertRaises(ValueError, P('a/b').with_stem, '.')
- def test_relative_to_several_args(self):
- P = self.cls
- p = P('a/b')
- with self.assertWarns(DeprecationWarning):
- p.relative_to('a', 'b')
- p.relative_to('a', 'b', walk_up=True)
-
- def test_is_relative_to_several_args(self):
- P = self.cls
- p = P('a/b')
- with self.assertWarns(DeprecationWarning):
- p.is_relative_to('a', 'b')
-
def test_is_reserved_deprecated(self):
P = self.cls
p = P('a/b')
diff --git
a/Misc/NEWS.d/next/Library/2024-05-08-18-59-19.gh-issue-78707._Lz1sw.rst
b/Misc/NEWS.d/next/Library/2024-05-08-18-59-19.gh-issue-78707._Lz1sw.rst
new file mode 100644
index 00000000000000..c73bab97b75838
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-05-08-18-59-19.gh-issue-78707._Lz1sw.rst
@@ -0,0 +1,3 @@
+Drop support for passing additional positional arguments to
+:meth:`pathlib.PurePath.relative_to` and
+:meth:`~pathlib.PurePath.is_relative_to`.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]