From 780fb1c424eca64b460d61909192b6612dbc9174 Mon Sep 17 00:00:00 2001 From: barneygale Date: Sat, 28 Oct 2023 23:50:04 +0100 Subject: [PATCH] Use `_from_parsed_parts()` to return pre-parsed path. --- Lib/pathlib.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/pathlib.py b/Lib/pathlib.py index 4e6d5b23102457..e2dc0bef429021 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -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 == '..':