MCPcopy Index your code
hub / github.com/python/cpython / joinpath

Method joinpath

Lib/importlib/resources/abc.py:104–127  ·  view source on GitHub ↗

Return Traversable resolved with any descendants applied. Each descendant should be a path segment relative to self and each may contain multiple levels separated by ``posixpath.sep`` (``/``).

(self, *descendants: StrPath)

Source from the content-addressed store, hash-verified

102 """
103
104 def joinpath(self, *descendants: StrPath) -> "Traversable":
105 """
106 Return Traversable resolved with any descendants applied.
107
108 Each descendant should be a path segment relative to self
109 and each may contain multiple levels separated by
110 ``posixpath.sep`` (``/``).
111 """
112 if not descendants:
113 return self
114 names = itertools.chain.from_iterable(
115 path.parts for path in map(pathlib.PurePosixPath, descendants)
116 )
117 target = next(names)
118 matches = (
119 traversable for traversable in self.iterdir() if traversable.name == target
120 )
121 try:
122 match = next(matches)
123 except StopIteration:
124 raise TraversalError(
125 "Target not found during traversal.", target, list(names)
126 )
127 return match.joinpath(*names)
128
129 def __truediv__(self, child: StrPath) -> "Traversable":
130 """

Callers 5

__truediv__Method · 0.95
_get_resourceFunction · 0.45
_write_contentsFunction · 0.45
open_resourceMethod · 0.45
is_resourceMethod · 0.45

Calls 3

iterdirMethod · 0.95
TraversalErrorClass · 0.85
listClass · 0.85

Tested by

no test coverage detected