From b979a2f1133599d418cd8e546c7a84f11ccbd8bc Mon Sep 17 00:00:00 2001 From: Sadhana Srinivasan Date: Mon, 20 Apr 2020 00:45:59 +0200 Subject: [PATCH 1/3] Better error for PurePath.relative_to() from pathlib Changed the error message to be more informative and updated the docs accordingly. --- Doc/library/pathlib.rst | 5 ++++- Lib/pathlib.py | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index dead49b630dcdf..4047e9894c3a06 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -551,7 +551,10 @@ Pure paths provide the following methods and properties: File "", line 1, in File "pathlib.py", line 694, in relative_to .format(str(self), str(formatted))) - ValueError: '/etc/passwd' does not start with '/usr' + ValueError: '/etc/passwd' is not in the subpath of '/usr' OR one path is relative and the other absolute. + + + NOTE: This function is part of :class:`PurePath` and works with strings. It does not check or access the underlying file structure. .. method:: PurePath.with_name(name) diff --git a/Lib/pathlib.py b/Lib/pathlib.py index f98d69eb04ac31..9f5e27b91178e6 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -922,7 +922,8 @@ def relative_to(self, *other): cf = self._flavour.casefold_parts if (root or drv) if n == 0 else cf(abs_parts[:n]) != cf(to_abs_parts): formatted = self._format_parsed_parts(to_drv, to_root, to_parts) - raise ValueError("{!r} does not start with {!r}" + raise ValueError("{!r} is not in the subpath of {!r}" + " OR one path is relative and the other is absolute." .format(str(self), str(formatted))) return self._from_parsed_parts('', root if n == 1 else '', abs_parts[n:]) From 3c05582ad797d994873a6a8976f6c7eaba834630 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 20 Apr 2020 22:08:37 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NEWS.d/next/Library/2020-04-20-22-08-36.bpo-23082.iX90Id.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2020-04-20-22-08-36.bpo-23082.iX90Id.rst diff --git a/Misc/NEWS.d/next/Library/2020-04-20-22-08-36.bpo-23082.iX90Id.rst b/Misc/NEWS.d/next/Library/2020-04-20-22-08-36.bpo-23082.iX90Id.rst new file mode 100644 index 00000000000000..13ed0defe529cf --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-04-20-22-08-36.bpo-23082.iX90Id.rst @@ -0,0 +1 @@ +Updated the error message and docs of PurePath.relative_to() to better reflect the function behaviour. \ No newline at end of file From e7f0ab1f3226b2762dd6e12c3cef36bcb1e1aff7 Mon Sep 17 00:00:00 2001 From: rotuna Date: Tue, 21 Apr 2020 00:09:52 +0200 Subject: [PATCH 3/3] fixed whitespace issues --- Doc/library/pathlib.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index 4047e9894c3a06..7d7924252bf782 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -553,8 +553,7 @@ Pure paths provide the following methods and properties: .format(str(self), str(formatted))) ValueError: '/etc/passwd' is not in the subpath of '/usr' OR one path is relative and the other absolute. - - NOTE: This function is part of :class:`PurePath` and works with strings. It does not check or access the underlying file structure. + NOTE: This function is part of :class:`PurePath` and works with strings. It does not check or access the underlying file structure. .. method:: PurePath.with_name(name)