@@ -805,6 +805,9 @@ def realpath(path, *, strict=False):
805805def relpath (path , start = None ):
806806 """Return a relative version of a path"""
807807 path = os .fspath (path )
808+ if not path :
809+ raise ValueError ("no path specified" )
810+
808811 if isinstance (path , bytes ):
809812 sep = b'\\ '
810813 curdir = b'.'
@@ -816,22 +819,20 @@ def relpath(path, start=None):
816819
817820 if start is None :
818821 start = curdir
822+ else :
823+ start = os .fspath (start )
819824
820- if not path :
821- raise ValueError ("no path specified" )
822-
823- start = os .fspath (start )
824825 try :
825- start_abs = abspath (normpath ( start ) )
826- path_abs = abspath (normpath ( path ) )
826+ start_abs = abspath (start )
827+ path_abs = abspath (path )
827828 start_drive , _ , start_rest = splitroot (start_abs )
828829 path_drive , _ , path_rest = splitroot (path_abs )
829830 if normcase (start_drive ) != normcase (path_drive ):
830831 raise ValueError ("path is on mount %r, start on mount %r" % (
831832 path_drive , start_drive ))
832833
833- start_list = [ x for x in start_rest .split (sep ) if x ]
834- path_list = [ x for x in path_rest .split (sep ) if x ]
834+ start_list = start_rest .split (sep ) if start_rest else [ ]
835+ path_list = path_rest .split (sep ) if path_rest else [ ]
835836 # Work out how much of the filepath is shared by start and path.
836837 i = 0
837838 for e1 , e2 in zip (start_list , path_list ):
@@ -842,7 +843,7 @@ def relpath(path, start=None):
842843 rel_list = [pardir ] * (len (start_list )- i ) + path_list [i :]
843844 if not rel_list :
844845 return curdir
845- return join (* rel_list )
846+ return sep . join (rel_list )
846847 except (TypeError , ValueError , AttributeError , BytesWarning , DeprecationWarning ):
847848 genericpath ._check_arg_types ('relpath' , path , start )
848849 raise
0 commit comments