]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-117584: Raise TypeError for non-paths in posixpath.relpath() (GH-117585)
authorNice Zombies <nineteendo19d0@gmail.com>
Sun, 7 Apr 2024 09:00:08 +0000 (11:00 +0200)
committerGitHub <noreply@github.com>
Sun, 7 Apr 2024 09:00:08 +0000 (12:00 +0300)
Lib/posixpath.py
Lib/test/test_posixpath.py
Misc/NEWS.d/next/Core and Builtins/2024-04-06-16-42-34.gh-issue-117584.hqk9Hn.rst [new file with mode: 0644]

index 0e8bb5ab10d916c8728194815cac0863db15a21a..b7fbdff20cac99cc476782a135497269cd17f6a8 100644 (file)
@@ -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'/'
index 807f985f7f4df786e9a1a2afda496f69f05cf400..ff78410738022db78744afc238f414e22d5ef421 100644 (file)
@@ -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 (file)
index 0000000..fd6a609
--- /dev/null
@@ -0,0 +1 @@
+Raise :exc:`TypeError` for non-paths in :func:`posixpath.relpath()`.