[importlib] Traversable joinpath and __truediv__ allows StrPath (#15108)

This commit is contained in:
Dylan Baker
2025-12-11 03:33:37 -08:00
committed by GitHub
parent de81abbf31
commit d9f078f618
3 changed files with 7 additions and 5 deletions
+2 -2
View File
@@ -52,9 +52,9 @@ if sys.version_info >= (3, 10):
def is_file(self) -> Literal[False]: ...
if sys.version_info >= (3, 12):
def joinpath(self, *descendants: str) -> abc.Traversable: ...
def joinpath(self, *descendants: StrPath) -> abc.Traversable: ...
elif sys.version_info >= (3, 11):
def joinpath(self, child: str) -> abc.Traversable: ... # type: ignore[override]
def joinpath(self, child: StrPath) -> abc.Traversable: ... # type: ignore[override]
else:
def joinpath(self, child: str) -> abc.Traversable: ...
+3 -2
View File
@@ -1,4 +1,5 @@
import sys
from _typeshed import StrPath
from abc import ABCMeta, abstractmethod
from collections.abc import Iterator
from io import BufferedReader
@@ -24,7 +25,7 @@ if sys.version_info >= (3, 11):
@abstractmethod
def iterdir(self) -> Iterator[Traversable]: ...
@abstractmethod
def joinpath(self, *descendants: str) -> Traversable: ...
def joinpath(self, *descendants: StrPath) -> Traversable: ...
# The documentation and runtime protocol allows *args, **kwargs arguments,
# but this would mean that all implementers would have to support them,
@@ -38,7 +39,7 @@ if sys.version_info >= (3, 11):
@property
@abstractmethod
def name(self) -> str: ...
def __truediv__(self, child: str, /) -> Traversable: ...
def __truediv__(self, child: StrPath, /) -> Traversable: ...
@abstractmethod
def read_bytes(self) -> bytes: ...
@abstractmethod
+2 -1
View File
@@ -1,5 +1,6 @@
import abc
import sys
from _typeshed import StrPath
from collections.abc import Iterator
from io import TextIOWrapper
from typing import IO, Any, BinaryIO, Literal, NoReturn, overload
@@ -50,7 +51,7 @@ if sys.version_info >= (3, 11):
def iterdir(self) -> Iterator[ResourceHandle | ResourceContainer]: ...
def open(self, *args: Never, **kwargs: Never) -> NoReturn: ... # type: ignore[override]
if sys.version_info < (3, 12):
def joinpath(self, *descendants: str) -> Traversable: ...
def joinpath(self, *descendants: StrPath) -> Traversable: ...
class TraversableReader(TraversableResources, SimpleReader, metaclass=abc.ABCMeta):
def files(self) -> ResourceContainer: ...