Skip to content

Commit f772d0d

Browse files
authored
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.
1 parent 13d7cf9 commit f772d0d

File tree

4 files changed

+15
-29
lines changed

4 files changed

+15
-29
lines changed

Doc/whatsnew/3.14.rst

+8
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ email
114114
* The *isdst* parameter has been removed from :func:`email.utils.localtime`.
115115
(Contributed by Hugo van Kemenade in :gh:`118798`.)
116116

117+
pathlib
118+
-------
119+
120+
* Remove support for passing additional positional arguments to
121+
:meth:`pathlib.PurePath.relative_to` and
122+
:meth:`~pathlib.PurePath.is_relative_to`. In previous versions, any such
123+
arguments are joined onto *other*.
124+
117125
Others
118126
------
119127

Lib/pathlib/_local.py

+4-16
Original file line numberDiff line numberDiff line change
@@ -362,21 +362,15 @@ def with_name(self, name):
362362
tail[-1] = name
363363
return self._from_parsed_parts(self.drive, self.root, tail)
364364

365-
def relative_to(self, other, /, *_deprecated, walk_up=False):
365+
def relative_to(self, other, *, walk_up=False):
366366
"""Return the relative path to another path identified by the passed
367367
arguments. If the operation is not possible (because this is not
368368
related to the other path), raise ValueError.
369369
370370
The *walk_up* parameter controls whether `..` may be used to resolve
371371
the path.
372372
"""
373-
if _deprecated:
374-
msg = ("support for supplying more than one positional argument "
375-
"to pathlib.PurePath.relative_to() is deprecated and "
376-
"scheduled for removal in Python 3.14")
377-
warnings.warn(msg, DeprecationWarning, stacklevel=2)
378-
other = self.with_segments(other, *_deprecated)
379-
elif not isinstance(other, PurePath):
373+
if not isinstance(other, PurePath):
380374
other = self.with_segments(other)
381375
for step, path in enumerate(chain([other], other.parents)):
382376
if path == self or path in self.parents:
@@ -390,16 +384,10 @@ def relative_to(self, other, /, *_deprecated, walk_up=False):
390384
parts = ['..'] * step + self._tail[len(path._tail):]
391385
return self._from_parsed_parts('', '', parts)
392386

393-
def is_relative_to(self, other, /, *_deprecated):
387+
def is_relative_to(self, other):
394388
"""Return True if the path is relative to another path or False.
395389
"""
396-
if _deprecated:
397-
msg = ("support for supplying more than one argument to "
398-
"pathlib.PurePath.is_relative_to() is deprecated and "
399-
"scheduled for removal in Python 3.14")
400-
warnings.warn(msg, DeprecationWarning, stacklevel=2)
401-
other = self.with_segments(other, *_deprecated)
402-
elif not isinstance(other, PurePath):
390+
if not isinstance(other, PurePath):
403391
other = self.with_segments(other)
404392
return other == self or other in self.parents
405393

Lib/test/test_pathlib/test_pathlib.py

-13
Original file line numberDiff line numberDiff line change
@@ -311,19 +311,6 @@ def test_with_stem_empty(self):
311311
self.assertRaises(ValueError, P('a/b').with_stem, '')
312312
self.assertRaises(ValueError, P('a/b').with_stem, '.')
313313

314-
def test_relative_to_several_args(self):
315-
P = self.cls
316-
p = P('a/b')
317-
with self.assertWarns(DeprecationWarning):
318-
p.relative_to('a', 'b')
319-
p.relative_to('a', 'b', walk_up=True)
320-
321-
def test_is_relative_to_several_args(self):
322-
P = self.cls
323-
p = P('a/b')
324-
with self.assertWarns(DeprecationWarning):
325-
p.is_relative_to('a', 'b')
326-
327314
def test_is_reserved_deprecated(self):
328315
P = self.cls
329316
p = P('a/b')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Drop support for passing additional positional arguments to
2+
:meth:`pathlib.PurePath.relative_to` and
3+
:meth:`~pathlib.PurePath.is_relative_to`.

0 commit comments

Comments
 (0)