def fspath(path):
fsp = getattr(path, '__fspath__', None)
if fsp is not None and callable(fsp):
path = fsp()
if not isinstance(path, (str, bytes)):
raise TypeError(
'expected {}() to return str or bytes, not {}'.format(
fsp.__qualname__, type(path).__name__
))
return path
elif isinstance(path, (str, bytes)):
return path
else:
raise TypeError(
'expected str, bytes or path-like object, not {}'.format(
type(path).__name__
)
)
评论列表
文章目录