From: Nice Zombies Date: Sun, 7 Apr 2024 09:00:08 +0000 (+0200) Subject: gh-117584: Raise TypeError for non-paths in posixpath.relpath() (GH-117585) X-Git-Tag: v3.13.0a6~23 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=733e56ef9656dd79055acc2a3cecaf6054a45b6c;p=thirdparty%2FPython%2Fcpython.git gh-117584: Raise TypeError for non-paths in posixpath.relpath() (GH-117585) --- diff --git a/Lib/posixpath.py b/Lib/posixpath.py index 0e8bb5ab10d9..b7fbdff20cac 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 807f985f7f4d..ff7841073802 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 000000000000..fd6a6097a891 --- /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()`.