Skip to content

Commit a3db1b9

Browse files
committedMay 8, 2024·
pythonGH-78707: Drop deprecated pathlib.PurePath.[is_]relative_to() arguments
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 aac6b01 commit a3db1b9

File tree

3 files changed

+11
-29
lines changed

3 files changed

+11
-29
lines changed
 

‎Doc/whatsnew/3.14.rst

+7
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ Deprecated
101101
Removed
102102
=======
103103

104+
pathlib
105+
-------
106+
107+
* Remove support for passing additional positional arguments to
108+
:meth:`~pathlib.PurePath.is_relative_to` and
109+
:meth:`~pathlib.PurePath.relative_to`. In previous versions, any such
110+
arguments are joined onto *other*.
104111

105112

106113
Porting to Python 3.14

‎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')

0 commit comments

Comments
 (0)
Please sign in to comment.