Skip to content

Commit

Permalink
pythongh-117584: Raise TypeError for non-paths in posixpath.relpath() (
Browse files Browse the repository at this point in the history
  • Loading branch information
nineteendo authored Apr 7, 2024
1 parent 62aeb0e commit 733e56e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Lib/posixpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'/'
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_posixpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Raise :exc:`TypeError` for non-paths in :func:`posixpath.relpath()`.

0 comments on commit 733e56e

Please sign in to comment.