Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-78707: Drop deprecated pathlib.PurePath.[is_]relative_to() arguments #118780

Merged
merged 5 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
barneygale marked this conversation as resolved.
Show resolved Hide resolved

* 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
------

Expand Down
20 changes: 4 additions & 16 deletions Lib/pathlib/_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,21 +362,15 @@ 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.

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:
Expand All @@ -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

Expand Down
13 changes: 0 additions & 13 deletions Lib/test/test_pathlib/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Drop support for passing additional positional arguments to
:meth:`pathlib.PurePath.relative_to` and
:meth:`~pathlib.PurePath.is_relative_to`.
barneygale marked this conversation as resolved.
Show resolved Hide resolved
Loading