summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNice Zombies <nineteendo19d0@gmail.com>2024-04-07 09:00:08 (GMT)
committerGitHub <noreply@github.com>2024-04-07 09:00:08 (GMT)
commit733e56ef9656dd79055acc2a3cecaf6054a45b6c (patch)
treeb11a7a912c8b038ebe8a0d54e257f9864e8a28d4
parent62aeb0ee69b06091396398de56dcb755ca3b9dc9 (diff)
downloadcpython-733e56ef9656dd79055acc2a3cecaf6054a45b6c.zip
cpython-733e56ef9656dd79055acc2a3cecaf6054a45b6c.tar.gz
cpython-733e56ef9656dd79055acc2a3cecaf6054a45b6c.tar.bz2
gh-117584: Raise TypeError for non-paths in posixpath.relpath() (GH-117585)
-rw-r--r--Lib/posixpath.py2
-rw-r--r--Lib/test/test_posixpath.py1
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2024-04-06-16-42-34.gh-issue-117584.hqk9Hn.rst1
3 files changed, 3 insertions, 1 deletions
diff --git a/Lib/posixpath.py b/Lib/posixpath.py
index 0e8bb5a..b7fbdff 100644
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -502,10 +502,10 @@ supports_unicode_filenames = (sys.platform == 'darwin')
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 807f985..ff78410 100644
--- a/Lib/test/test_posixpath.py
+++ b/Lib/test/test_posixpath.py
@@ -650,6 +650,7 @@ class PosixPathTest(unittest.TestCase):
(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")
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 0000000..fd6a609
--- /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 :exc:`TypeError` for non-paths in :func:`posixpath.relpath()`.