File tree 1 file changed +12
-2
lines changed 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,10 @@ def contents(self) -> Iterable[str]:
52
52
raise FileNotFoundError
53
53
54
54
55
+ class TraversalError (Exception ):
56
+ pass
57
+
58
+
55
59
@runtime_checkable
56
60
class Traversable (Protocol ):
57
61
"""
@@ -108,9 +112,15 @@ def joinpath(self, *descendants: StrPath) -> "Traversable":
108
112
path .parts for path in map (pathlib .PurePosixPath , descendants )
109
113
)
110
114
target = next (names )
111
- return next (
115
+ matches = (
112
116
traversable for traversable in self .iterdir () if traversable .name == target
113
- ).joinpath (* names )
117
+ )
118
+ try :
119
+ return next (matches ).joinpath (* names )
120
+ except StopIteration :
121
+ raise TraversalError (
122
+ "Target not found during traversal." , target , list (names )
123
+ )
114
124
115
125
def __truediv__ (self , child : StrPath ) -> "Traversable" :
116
126
"""
You can’t perform that action at this time.
0 commit comments