Skip to content
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
5 changes: 4 additions & 1 deletion Lib/pathlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@ def relative_to(self, other, /, *_deprecated, walk_up=False):
"scheduled for removal in Python 3.14")
warnings.warn(msg, DeprecationWarning, stacklevel=2)
other = self.with_segments(other, *_deprecated)
return _abc.PurePathBase.relative_to(self, other, walk_up=walk_up)
path = _abc.PurePathBase.relative_to(self, other, walk_up=walk_up)
path._drv = path._root = ''
path._tail_cached = path._raw_paths.copy()
return path

def is_relative_to(self, other, /, *_deprecated):
"""Return True if the path is relative to another path or False.
Expand Down
2 changes: 1 addition & 1 deletion Lib/pathlib/_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def relative_to(self, other, *, walk_up=False):
else:
raise ValueError(f"{str(self)!r} and {str(other)!r} have different anchors")
parts = ['..'] * step + self._tail[len(path._tail):]
return self._from_parsed_parts('', '', parts)
return self.with_segments(*parts)

def is_relative_to(self, other):
"""Return True if the path is relative to another path or False.
Expand Down