diff options
Diffstat (limited to 'Lib/pathlib.py')
-rw-r--r-- | Lib/pathlib.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py index b99bf6e..65631b7 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -679,10 +679,12 @@ class PurePath(object): for step, path in enumerate([other] + list(other.parents)): if self.is_relative_to(path): break + elif not walk_up: + raise ValueError(f"{str(self)!r} is not in the subpath of {str(other)!r}") + elif path.name == '..': + raise ValueError(f"'..' segment in {str(other)!r} cannot be walked") else: raise ValueError(f"{str(self)!r} and {str(other)!r} have different anchors") - if step and not walk_up: - raise ValueError(f"{str(self)!r} is not in the subpath of {str(other)!r}") parts = ['..'] * step + self._tail[len(path._tail):] return self.with_segments(*parts) |