|
23 | 23 | _WP = TypeVar("_WP", bound="_WritablePath") |
24 | 24 |
|
25 | 25 |
|
26 | | -def _explode_path(path: str, split: Callable[[str], tuple[str, str]]) -> tuple[str, list[str]]: |
| 26 | +def _explode_path(path: str, parser: "_PathParser") -> tuple[str, list[str]]: |
27 | 27 | """ |
28 | 28 | Split the path into a 2-tuple (anchor, parts), where *anchor* is the |
29 | 29 | uppermost parent of the path (equivalent to path.parents[-1]), and |
30 | 30 | *parts* is a reversed list of parts following the anchor. |
31 | 31 | """ |
| 32 | + split = parser.split |
32 | 33 | parent, name = split(path) |
33 | 34 | names = [] |
34 | 35 | while path != parent: |
@@ -99,7 +100,7 @@ def __str__(self) -> str: |
99 | 100 | @property |
100 | 101 | def anchor(self) -> str: |
101 | 102 | """The concatenation of the drive and root, or ''.""" |
102 | | - return _explode_path(str(self), self.parser.split)[0] |
| 103 | + return _explode_path(str(self), self.parser)[0] |
103 | 104 |
|
104 | 105 | @property |
105 | 106 | def name(self) -> str: |
@@ -173,7 +174,7 @@ def with_suffix(self, suffix: str) -> Self: |
173 | 174 | def parts(self) -> Sequence[str]: |
174 | 175 | """An object providing sequence-like access to the |
175 | 176 | components in the filesystem path.""" |
176 | | - anchor, parts = _explode_path(str(self), self.parser.split) |
| 177 | + anchor, parts = _explode_path(str(self), self.parser) |
177 | 178 | if anchor: |
178 | 179 | parts.append(anchor) |
179 | 180 | return tuple(reversed(parts)) |
@@ -289,7 +290,7 @@ def glob(self, pattern: str, *, recurse_symlinks: Literal[True] = True) -> Itera |
289 | 290 | """Iterate over this subtree and yield all existing files (of any |
290 | 291 | kind, including directories) matching the given relative pattern. |
291 | 292 | """ |
292 | | - anchor, parts = _explode_path(pattern, self.parser.split) |
| 293 | + anchor, parts = _explode_path(pattern, self.parser) |
293 | 294 | if anchor: |
294 | 295 | raise NotImplementedError("Non-relative patterns are unsupported") |
295 | 296 | elif not parts: |
|
0 commit comments