File tree Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -215,18 +215,25 @@ def vfspath(path):
215215 Return the string representation of a virtual path object.
216216 """
217217 try :
218- return os .fspath (path )
218+ path_str = os .fspath (path )
219219 except TypeError :
220220 pass
221- cls = type (path )
221+ else :
222+ if isinstance (path_str , str ):
223+ return path_str
224+
225+ path_type = type (path )
222226 try :
223- attr = cls .__vfspath__
227+ path_str = path_type .__vfspath__ ( path )
224228 except AttributeError :
225- pass
229+ if hasattr (path_type , '__fspath__' ):
230+ raise
226231 else :
227- return attr (path )
232+ if isinstance (path_str , str ):
233+ return path_str
228234
229- raise TypeError (f"{ cls .__name__ } can't be converted to a path" )
235+ raise TypeError ("expected str, os.PathLike[str] or JoinablePath "
236+ "object, not " + path_type .__name__ )
230237
231238
232239def ensure_distinct_paths (source , target ):
@@ -334,7 +341,7 @@ class _PathInfoBase:
334341 __slots__ = ('_path' , '_stat_result' , '_lstat_result' )
335342
336343 def __init__ (self , path ):
337- self ._path = os . fspath (path )
344+ self ._path = str (path )
338345
339346 def __repr__ (self ):
340347 path_type = "WindowsPath" if os .name == "nt" else "PosixPath"
Original file line number Diff line number Diff line change 88from .support import is_pypi
99from .support .lexical_path import LexicalWindowsPath
1010
11-
1211if is_pypi :
1312 from pathlib_abc import vfspath
1413else :
You can’t perform that action at this time.
0 commit comments