MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _fspath

Function _fspath

tools/python-3.11.9-amd64/Lib/os.py:1036–1063  ·  view source on GitHub ↗

Return the path representation of a path-like object. If str or bytes is passed in, it is returned unchanged. Otherwise the os.PathLike interface is used to get the path representation. If the path representation is not str or bytes, TypeError is raised. If the provided path is

(path)

Source from the content-addressed store, hash-verified

1034# For testing purposes, make sure the function is available when the C
1035# implementation exists.
1036def _fspath(path):
1037 """Return the path representation of a path-like object.
1038
1039 If str or bytes is passed in, it is returned unchanged. Otherwise the
1040 os.PathLike interface is used to get the path representation. If the
1041 path representation is not str or bytes, TypeError is raised. If the
1042 provided path is not str, bytes, or os.PathLike, TypeError is raised.
1043 """
1044 if isinstance(path, (str, bytes)):
1045 return path
1046
1047 # Work from the object's type to match method resolution of other magic
1048 # methods.
1049 path_type = type(path)
1050 try:
1051 path_repr = path_type.__fspath__(path)
1052 except AttributeError:
1053 if hasattr(path_type, '__fspath__'):
1054 raise
1055 else:
1056 raise TypeError("expected str, bytes or os.PathLike object, "
1057 "not " + path_type.__name__)
1058 if isinstance(path_repr, (str, bytes)):
1059 return path_repr
1060 else:
1061 raise TypeError("expected {}.__fspath__() to return str or bytes, "
1062 "not {}".format(path_type.__name__,
1063 type(path_repr).__name__))
1064
1065# If there is no C implementation, make the pure Python version the
1066# implementation as transparently as possible.

Callers

nothing calls this directly

Calls 3

typeClass · 0.50
__fspath__Method · 0.45
formatMethod · 0.45

Tested by

no test coverage detected