https://github.com/python/cpython/commit/733e56ef9656dd79055acc2a3cecaf6054a45b6c
commit: 733e56ef9656dd79055acc2a3cecaf6054a45b6c
branch: main
author: Nice Zombies <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2024-04-07T12:00:08+03:00
summary:

gh-117584: Raise TypeError for non-paths in posixpath.relpath() (GH-117585)

files:
A Misc/NEWS.d/next/Core and 
Builtins/2024-04-06-16-42-34.gh-issue-117584.hqk9Hn.rst
M Lib/posixpath.py
M Lib/test/test_posixpath.py

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")
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..fd6a6097a89154
--- /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()`.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to