Skip to content

Commit 4745c44

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 4745c44

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

stdlib/importlib/readers.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ 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):
57-
def joinpath(self, child: str) -> abc.Traversable: ... # type: ignore[override]
57+
def joinpath(self, child: StrPath) -> abc.Traversable: ... # type: ignore[override]
5858
else:
5959
def joinpath(self, child: str) -> abc.Traversable: ...
6060

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

stdlib/importlib/resources/simple.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ from io import TextIOWrapper
55
from typing import IO, Any, BinaryIO, Literal, NoReturn, overload
66
from typing_extensions import Never
77

8+
from _typeshed import StrPath
9+
810
if sys.version_info >= (3, 11):
911
from .abc import Traversable, TraversableResources
1012

@@ -50,7 +52,7 @@ if sys.version_info >= (3, 11):
5052
def iterdir(self) -> Iterator[ResourceHandle | ResourceContainer]: ...
5153
def open(self, *args: Never, **kwargs: Never) -> NoReturn: ... # type: ignore[override]
5254
if sys.version_info < (3, 12):
53-
def joinpath(self, *descendants: str) -> Traversable: ...
55+
def joinpath(self, *descendants: StrPath) -> Traversable: ...
5456

5557
class TraversableReader(TraversableResources, SimpleReader, metaclass=abc.ABCMeta):
5658
def files(self) -> ResourceContainer: ...

0 commit comments

Comments
 (0)