Skip to content

Commit e535776

Browse files
committed
[stdlib] Align Traversable joinpath and __truediv__ with CPython
The CPython implementation accepts `str | os.PathLike[str]`, typeshed only accepts `str`. CPython 3.13 implementations: https://github.com/python/cpython/blob/59f247e43bc93c607a5793c220bcaafb712cf542/Lib/importlib/resources/abc.py#L104 https://github.com/python/cpython/blob/59f247e43bc93c607a5793c220bcaafb712cf542/Lib/importlib/resources/abc.py#L129
1 parent 5d41fd6 commit e535776

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

stdlib/importlib/readers.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ if sys.version_info >= (3, 10):
5252
def is_file(self) -> Literal[False]: ...
5353

5454
if sys.version_info >= (3, 12):
55-
def joinpath(self, *descendants: str) -> abc.Traversable: ...
55+
def joinpath(self, *descendants: StrPath) -> abc.Traversable: ...
5656
elif sys.version_info >= (3, 11):
5757
def joinpath(self, child: str) -> abc.Traversable: ... # type: ignore[override]
5858
else:

stdlib/importlib/resources/abc.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ from collections.abc import Iterator
44
from io import BufferedReader
55
from typing import IO, Any, Literal, Protocol, overload, runtime_checkable
66

7+
from _typeshed import StrPath
8+
79
if sys.version_info >= (3, 11):
810
class ResourceReader(metaclass=ABCMeta):
911
@abstractmethod
@@ -24,7 +26,7 @@ if sys.version_info >= (3, 11):
2426
@abstractmethod
2527
def iterdir(self) -> Iterator[Traversable]: ...
2628
@abstractmethod
27-
def joinpath(self, *descendants: str) -> Traversable: ...
29+
def joinpath(self, *descendants: StrPath) -> Traversable: ...
2830

2931
# The documentation and runtime protocol allows *args, **kwargs arguments,
3032
# but this would mean that all implementers would have to support them,
@@ -38,7 +40,7 @@ if sys.version_info >= (3, 11):
3840
@property
3941
@abstractmethod
4042
def name(self) -> str: ...
41-
def __truediv__(self, child: str, /) -> Traversable: ...
43+
def __truediv__(self, child: StrPath, /) -> Traversable: ...
4244
@abstractmethod
4345
def read_bytes(self) -> bytes: ...
4446
@abstractmethod

0 commit comments

Comments
 (0)