From 1cd1289e1e5dc893db2f2a417633accfbe83a2dd Mon Sep 17 00:00:00 2001 From: nineteendo Date: Sat, 6 Apr 2024 18:40:19 +0200 Subject: [PATCH 1/5] Raise TypeError for non-paths in `posixpath.relpath()` --- Lib/posixpath.py | 2 +- Lib/test/test_posixpath.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/posixpath.py b/Lib/posixpath.py index 0e8bb5ab10d916..b7fbdff20cac99 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -502,10 +502,10 @@ def realpath(filename, *, strict=False): def relpath(path, start=None): """Return a relative version of a path""" + path = os.fspath(path) if not path: raise ValueError("no path specified") - path = os.fspath(path) if isinstance(path, bytes): curdir = b'.' sep = b'/' diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py index 807f985f7f4df7..ff78410738022d 100644 --- a/Lib/test/test_posixpath.py +++ b/Lib/test/test_posixpath.py @@ -650,6 +650,7 @@ def test_relpath(self): (real_getcwd, os.getcwd) = (os.getcwd, lambda: r"/home/user/bar") try: curdir = os.path.split(os.getcwd())[-1] + self.assertRaises(TypeError, posixpath.relpath, None) self.assertRaises(ValueError, posixpath.relpath, "") self.assertEqual(posixpath.relpath("a"), "a") self.assertEqual(posixpath.relpath(posixpath.abspath("a")), "a") From 1b33d28c9fedaa3b2e82f28788dfc8ea8ca6ee7e Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sat, 6 Apr 2024 16:42:35 +0000 Subject: [PATCH 2/5] =?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 --- .../2024-04-06-16-42-34.gh-issue-117584.hqk9Hn.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2024-04-06-16-42-34.gh-issue-117584.hqk9Hn.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-04-06-16-42-34.gh-issue-117584.hqk9Hn.rst b/Misc/NEWS.d/next/Core and Builtins/2024-04-06-16-42-34.gh-issue-117584.hqk9Hn.rst new file mode 100644 index 00000000000000..c6abfe29673247 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2024-04-06-16-42-34.gh-issue-117584.hqk9Hn.rst @@ -0,0 +1 @@ +Raise TypeError for non-paths in :func:`posixpath.relpath()`. From 27d0c708eeff347e43a99d371f0c710bce49b292 Mon Sep 17 00:00:00 2001 From: Nice Zombies Date: Sat, 6 Apr 2024 18:46:36 +0200 Subject: [PATCH 3/5] Update Misc/NEWS.d/next/Core and Builtins/2024-04-06-16-42-34.gh-issue-117584.hqk9Hn.rst Co-authored-by: AN Long --- .../2024-04-06-16-42-34.gh-issue-117584.hqk9Hn.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-04-06-16-42-34.gh-issue-117584.hqk9Hn.rst b/Misc/NEWS.d/next/Core and Builtins/2024-04-06-16-42-34.gh-issue-117584.hqk9Hn.rst index c6abfe29673247..04ada3f220a1c4 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2024-04-06-16-42-34.gh-issue-117584.hqk9Hn.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2024-04-06-16-42-34.gh-issue-117584.hqk9Hn.rst @@ -1 +1 @@ -Raise TypeError for non-paths in :func:`posixpath.relpath()`. +Raise :exec:`TypeError` for non-paths in :func:`posixpath.relpath()`. From 77837f53a79209055f3d02c0de04c7bbdcbb5c1d Mon Sep 17 00:00:00 2001 From: nineteendo Date: Sat, 6 Apr 2024 18:53:28 +0200 Subject: [PATCH 4/5] Revert "Update Misc/NEWS.d/next/Core and Builtins/2024-04-06-16-42-34.gh-issue-117584.hqk9Hn.rst" This reverts commit 27d0c708eeff347e43a99d371f0c710bce49b292. --- .../2024-04-06-16-42-34.gh-issue-117584.hqk9Hn.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-04-06-16-42-34.gh-issue-117584.hqk9Hn.rst b/Misc/NEWS.d/next/Core and Builtins/2024-04-06-16-42-34.gh-issue-117584.hqk9Hn.rst index 04ada3f220a1c4..c6abfe29673247 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2024-04-06-16-42-34.gh-issue-117584.hqk9Hn.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2024-04-06-16-42-34.gh-issue-117584.hqk9Hn.rst @@ -1 +1 @@ -Raise :exec:`TypeError` for non-paths in :func:`posixpath.relpath()`. +Raise TypeError for non-paths in :func:`posixpath.relpath()`. From 6da601d96165cce6c23199721a1277c0ec584bc3 Mon Sep 17 00:00:00 2001 From: nineteendo Date: Sat, 6 Apr 2024 18:57:36 +0200 Subject: [PATCH 5/5] Update Misc/NEWS.d/next/Core and Builtins/2024-04-06-16-42-34.gh-issue-117584.hqk9Hn.rst Co-authored-by: AN Long --- .../2024-04-06-16-42-34.gh-issue-117584.hqk9Hn.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-04-06-16-42-34.gh-issue-117584.hqk9Hn.rst b/Misc/NEWS.d/next/Core and Builtins/2024-04-06-16-42-34.gh-issue-117584.hqk9Hn.rst index c6abfe29673247..fd6a6097a89154 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2024-04-06-16-42-34.gh-issue-117584.hqk9Hn.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2024-04-06-16-42-34.gh-issue-117584.hqk9Hn.rst @@ -1 +1 @@ -Raise TypeError for non-paths in :func:`posixpath.relpath()`. +Raise :exc:`TypeError` for non-paths in :func:`posixpath.relpath()`.