valueerrors for attrs not available outside of PurePathBase

This commit is contained in:
sneakers-the-rat 2024-09-23 16:32:13 -07:00
parent ea0e8127fa
commit 3afeb9bf3f
Signed by untrusted user who does not match committer: jonny
GPG key ID: 6DCB96EF1E4D232D

View file

@ -121,11 +121,13 @@ def relative_path(self: Path, other: Path, walk_up: bool = True) -> Path:
""" """
if not isinstance(other, Path): if not isinstance(other, Path):
other = self.with_segments(other) other = self.with_segments(other)
anchor0, parts0 = self._stack self_parts = self.parts
anchor1, parts1 = other._stack other_parts = other.parts
anchor0, parts0 = self_parts[0], list(reversed(self_parts[1:]))
anchor1, parts1 = other_parts[0], list(reversed(other_parts[1:]))
if anchor0 != anchor1: if anchor0 != anchor1:
raise ValueError( raise ValueError(
f"{self._raw_path!r} and {other._raw_path!r} have different anchors" f"{self!r} and {other!r} have different anchors"
) )
while parts0 and parts1 and parts0[-1] == parts1[-1]: while parts0 and parts1 and parts0[-1] == parts1[-1]:
parts0.pop() parts0.pop()
@ -135,10 +137,10 @@ def relative_path(self: Path, other: Path, walk_up: bool = True) -> Path:
pass pass
elif not walk_up: elif not walk_up:
raise ValueError( raise ValueError(
f"{self._raw_path!r} is not in the subpath of {other._raw_path!r}" f"{self!r} is not in the subpath of {other!r}"
) )
elif part == "..": elif part == "..":
raise ValueError(f"'..' segment in {other._raw_path!r} cannot be walked") raise ValueError(f"'..' segment in {other!r} cannot be walked")
else: else:
parts0.append("..") parts0.append("..")
return self.with_segments("", *reversed(parts0)) return self.with_segments("", *reversed(parts0))