Skip to content

Commit 733e56e

Browse files
authored
gh-117584: Raise TypeError for non-paths in posixpath.relpath() (GH-117585)
1 parent 62aeb0e commit 733e56e

File tree

3 files changed

+3
-1
lines changed

3 files changed

+3
-1
lines changed

Lib/posixpath.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -502,10 +502,10 @@ def realpath(filename, *, strict=False):
502502
def relpath(path, start=None):
503503
"""Return a relative version of a path"""
504504

505+
path = os.fspath(path)
505506
if not path:
506507
raise ValueError("no path specified")
507508

508-
path = os.fspath(path)
509509
if isinstance(path, bytes):
510510
curdir = b'.'
511511
sep = b'/'

Lib/test/test_posixpath.py

+1
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ def test_relpath(self):
650650
(real_getcwd, os.getcwd) = (os.getcwd, lambda: r"/home/user/bar")
651651
try:
652652
curdir = os.path.split(os.getcwd())[-1]
653+
self.assertRaises(TypeError, posixpath.relpath, None)
653654
self.assertRaises(ValueError, posixpath.relpath, "")
654655
self.assertEqual(posixpath.relpath("a"), "a")
655656
self.assertEqual(posixpath.relpath(posixpath.abspath("a")), "a")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Raise :exc:`TypeError` for non-paths in :func:`posixpath.relpath()`.

0 commit comments

Comments
 (0)