@@ -46,6 +46,7 @@ def normcase(s):
4646 """Normalize case of pathname.
4747
4848 Makes all characters lowercase and all slashes into backslashes."""
49+ s = os .fspath (s )
4950 try :
5051 if isinstance (s , bytes ):
5152 return s .replace (b'/' , b'\\ ' ).lower ()
@@ -66,12 +67,14 @@ def normcase(s):
6667
6768def isabs (s ):
6869 """Test whether a path is absolute"""
70+ s = os .fspath (s )
6971 s = splitdrive (s )[1 ]
7072 return len (s ) > 0 and s [0 ] in _get_bothseps (s )
7173
7274
7375# Join two (or more) paths.
7476def join (path , * paths ):
77+ path = os .fspath (path )
7578 if isinstance (path , bytes ):
7679 sep = b'\\ '
7780 seps = b'\\ /'
@@ -84,7 +87,7 @@ def join(path, *paths):
8487 if not paths :
8588 path [:0 ] + sep #23780: Ensure compatible data type even if p is null.
8689 result_drive , result_path = splitdrive (path )
87- for p in paths :
90+ for p in map ( os . fspath , paths ) :
8891 p_drive , p_path = splitdrive (p )
8992 if p_path and p_path [0 ] in seps :
9093 # Second path is absolute
@@ -136,6 +139,7 @@ def splitdrive(p):
136139 Paths cannot contain both a drive letter and a UNC path.
137140
138141 """
142+ p = os .fspath (p )
139143 if len (p ) >= 2 :
140144 if isinstance (p , bytes ):
141145 sep = b'\\ '
@@ -199,7 +203,7 @@ def split(p):
199203
200204 Return tuple (head, tail) where tail is everything after the final slash.
201205 Either part may be empty."""
202-
206+ p = os . fspath ( p )
203207 seps = _get_bothseps (p )
204208 d , p = splitdrive (p )
205209 # set i to index beyond p's last slash
@@ -218,6 +222,7 @@ def split(p):
218222# It is always true that root + ext == p.
219223
220224def splitext (p ):
225+ p = os .fspath (p )
221226 if isinstance (p , bytes ):
222227 return genericpath ._splitext (p , b'\\ ' , b'/' , b'.' )
223228 else :
@@ -278,6 +283,7 @@ def lexists(path):
278283def ismount (path ):
279284 """Test whether a path is a mount point (a drive root, the root of a
280285 share, or a mounted volume)"""
286+ path = os .fspath (path )
281287 seps = _get_bothseps (path )
282288 path = abspath (path )
283289 root , rest = splitdrive (path )
@@ -305,6 +311,7 @@ def expanduser(path):
305311 """Expand ~ and ~user constructs.
306312
307313 If user or $HOME is unknown, do nothing."""
314+ path = os .fspath (path )
308315 if isinstance (path , bytes ):
309316 tilde = b'~'
310317 else :
@@ -354,6 +361,7 @@ def expandvars(path):
354361 """Expand shell variables of the forms $var, ${var} and %var%.
355362
356363 Unknown variables are left unchanged."""
364+ path = os .fspath (path )
357365 if isinstance (path , bytes ):
358366 if b'$' not in path and b'%' not in path :
359367 return path
@@ -464,6 +472,7 @@ def expandvars(path):
464472
465473def normpath (path ):
466474 """Normalize path, eliminating double slashes, etc."""
475+ path = os .fspath (path )
467476 if isinstance (path , bytes ):
468477 sep = b'\\ '
469478 altsep = b'/'
@@ -518,6 +527,7 @@ def normpath(path):
518527except ImportError : # not running on Windows - mock up something sensible
519528 def abspath (path ):
520529 """Return the absolute version of a path."""
530+ path = os .fspath (path )
521531 if not isabs (path ):
522532 if isinstance (path , bytes ):
523533 cwd = os .getcwdb ()
@@ -531,6 +541,7 @@ def abspath(path):
531541 """Return the absolute version of a path."""
532542
533543 if path : # Empty path must return current working directory.
544+ path = os .fspath (path )
534545 try :
535546 path = _getfullpathname (path )
536547 except OSError :
@@ -549,6 +560,7 @@ def abspath(path):
549560
550561def relpath (path , start = None ):
551562 """Return a relative version of a path"""
563+ path = os .fspath (path )
552564 if isinstance (path , bytes ):
553565 sep = b'\\ '
554566 curdir = b'.'
@@ -564,6 +576,7 @@ def relpath(path, start=None):
564576 if not path :
565577 raise ValueError ("no path specified" )
566578
579+ start = os .fspath (start )
567580 try :
568581 start_abs = abspath (normpath (start ))
569582 path_abs = abspath (normpath (path ))
@@ -607,6 +620,7 @@ def commonpath(paths):
607620 if not paths :
608621 raise ValueError ('commonpath() arg is an empty sequence' )
609622
623+ paths = tuple (map (os .fspath , paths ))
610624 if isinstance (paths [0 ], bytes ):
611625 sep = b'\\ '
612626 altsep = b'/'
0 commit comments