Skip to content

Commit b923ce2

Browse files
committed
Refactor to converge descendants to a single type and rely on Path.parts for getting the parts.
1 parent df36958 commit b923ce2

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

importlib_resources/abc.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import abc
22
import io
3+
import itertools
4+
import pathlib
35
from typing import Any, BinaryIO, Iterable, Iterator, NoReturn, Text, Optional
46

57
from ._compat import runtime_checkable, Protocol, StrPath
@@ -102,7 +104,9 @@ def joinpath(self, *descendants: StrPath) -> "Traversable":
102104
"""
103105
if not descendants:
104106
return self
105-
names = (name for compound in descendants for name in compound.split('/'))
107+
names = itertools.chain.from_iterable(
108+
path.parts for path in map(pathlib.PurePosixPath, descendants)
109+
)
106110
target = next(names)
107111
return next(
108112
traversable for traversable in self.iterdir() if traversable.name == target

0 commit comments

Comments
 (0)