Skip to content

Commit

Permalink
Use _from_parsed_parts() to return pre-parsed path.
Browse files Browse the repository at this point in the history
  • Loading branch information
barneygale committed Oct 28, 2023
1 parent 4dfbfac commit 780fb1c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,8 @@ def relative_to(self, other, /, *_deprecated, walk_up=False):
other = self.with_segments(other)
for step, path in enumerate([other] + list(other.parents)):
if path == self or path in self.parents:
return self.with_segments(*['..'] * step, *self._tail[len(path._tail):])
tail = ['..'] * step + self._tail[len(path._tail):]
return self._from_parsed_parts('', '', tail)
elif not walk_up:
raise ValueError(f"{str(self)!r} is not in the subpath of {str(other)!r}")
elif path.name == '..':
Expand Down

0 comments on commit 780fb1c

Please sign in to comment.