bpo-23082: Better error message for PurePath.relative_to() from pathl… · python/cpython@318a18e · GitHub
Skip to content

Commit 318a18e

Browse files
bpo-23082: Better error message for PurePath.relative_to() from pathlib (GH-19611)
Co-authored-by: Sadhana Srinivasan <rotuna@Sadhanas-MBP.fritz.box> (cherry picked from commit 4483253) Co-authored-by: Rotuna <sadhanasrinivasan@protonmail.com>
1 parent 31084be commit 318a18e

3 files changed

Lines changed: 6 additions & 2 deletions

File tree

Doc/library/pathlib.rst

Lines changed: 3 additions & 1 deletion

Lib/pathlib.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,8 @@ def relative_to(self, *other):
922922
cf = self._flavour.casefold_parts
923923
if (root or drv) if n == 0 else cf(abs_parts[:n]) != cf(to_abs_parts):
924924
formatted = self._format_parsed_parts(to_drv, to_root, to_parts)
925-
raise ValueError("{!r} does not start with {!r}"
925+
raise ValueError("{!r} is not in the subpath of {!r}"
926+
" OR one path is relative and the other is absolute."
926927
.format(str(self), str(formatted)))
927928
return self._from_parsed_parts('', root if n == 1 else '',
928929
abs_parts[n:])
Lines changed: 1 addition & 0 deletions

0 commit comments

Comments
 (0)