Skip to content

Commit 4aa2540

Browse files
committed
Use _PathParser in _explode_path
1 parent b1de80e commit 4aa2540

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Lib/pathlib/types.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323
_WP = TypeVar("_WP", bound="_WritablePath")
2424

2525

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]]:
2727
"""
2828
Split the path into a 2-tuple (anchor, parts), where *anchor* is the
2929
uppermost parent of the path (equivalent to path.parents[-1]), and
3030
*parts* is a reversed list of parts following the anchor.
3131
"""
32+
split = parser.split
3233
parent, name = split(path)
3334
names = []
3435
while path != parent:
@@ -99,7 +100,7 @@ def __str__(self) -> str:
99100
@property
100101
def anchor(self) -> str:
101102
"""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]
103104

104105
@property
105106
def name(self) -> str:
@@ -173,7 +174,7 @@ def with_suffix(self, suffix: str) -> Self:
173174
def parts(self) -> Sequence[str]:
174175
"""An object providing sequence-like access to the
175176
components in the filesystem path."""
176-
anchor, parts = _explode_path(str(self), self.parser.split)
177+
anchor, parts = _explode_path(str(self), self.parser)
177178
if anchor:
178179
parts.append(anchor)
179180
return tuple(reversed(parts))
@@ -289,7 +290,7 @@ def glob(self, pattern: str, *, recurse_symlinks: Literal[True] = True) -> Itera
289290
"""Iterate over this subtree and yield all existing files (of any
290291
kind, including directories) matching the given relative pattern.
291292
"""
292-
anchor, parts = _explode_path(pattern, self.parser.split)
293+
anchor, parts = _explode_path(pattern, self.parser)
293294
if anchor:
294295
raise NotImplementedError("Non-relative patterns are unsupported")
295296
elif not parts:

0 commit comments

Comments
 (0)