From 4745c4464cff14388c326bc91b4f38f7c5d1d6a7 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 5 Dec 2025 11:23:25 -0800 Subject: [PATCH 1/2] [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 --- stdlib/importlib/readers.pyi | 4 ++-- stdlib/importlib/resources/abc.pyi | 6 ++++-- stdlib/importlib/resources/simple.pyi | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/stdlib/importlib/readers.pyi b/stdlib/importlib/readers.pyi index 4a6c73921535..0e7f7ce165c3 100644 --- a/stdlib/importlib/readers.pyi +++ b/stdlib/importlib/readers.pyi @@ -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: ... diff --git a/stdlib/importlib/resources/abc.pyi b/stdlib/importlib/resources/abc.pyi index 80d92a608604..4d0a352e980a 100644 --- a/stdlib/importlib/resources/abc.pyi +++ b/stdlib/importlib/resources/abc.pyi @@ -4,6 +4,8 @@ from collections.abc import Iterator from io import BufferedReader from typing import IO, Any, Literal, Protocol, overload, runtime_checkable +from _typeshed import StrPath + if sys.version_info >= (3, 11): class ResourceReader(metaclass=ABCMeta): @abstractmethod @@ -24,7 +26,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 +40,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 diff --git a/stdlib/importlib/resources/simple.pyi b/stdlib/importlib/resources/simple.pyi index c4c758111c2d..30cfecbc97ab 100644 --- a/stdlib/importlib/resources/simple.pyi +++ b/stdlib/importlib/resources/simple.pyi @@ -5,6 +5,8 @@ from io import TextIOWrapper from typing import IO, Any, BinaryIO, Literal, NoReturn, overload from typing_extensions import Never +from _typeshed import StrPath + if sys.version_info >= (3, 11): from .abc import Traversable, TraversableResources @@ -50,7 +52,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: ... From 7ee7991061f1712d69dbdf08c5fb36e0bdd06769 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 5 Dec 2025 20:41:23 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/importlib/resources/abc.pyi | 3 +-- stdlib/importlib/resources/simple.pyi | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/stdlib/importlib/resources/abc.pyi b/stdlib/importlib/resources/abc.pyi index 4d0a352e980a..9be594a7dc2f 100644 --- a/stdlib/importlib/resources/abc.pyi +++ b/stdlib/importlib/resources/abc.pyi @@ -1,11 +1,10 @@ import sys +from _typeshed import StrPath from abc import ABCMeta, abstractmethod from collections.abc import Iterator from io import BufferedReader from typing import IO, Any, Literal, Protocol, overload, runtime_checkable -from _typeshed import StrPath - if sys.version_info >= (3, 11): class ResourceReader(metaclass=ABCMeta): @abstractmethod diff --git a/stdlib/importlib/resources/simple.pyi b/stdlib/importlib/resources/simple.pyi index 30cfecbc97ab..946987c7312f 100644 --- a/stdlib/importlib/resources/simple.pyi +++ b/stdlib/importlib/resources/simple.pyi @@ -1,12 +1,11 @@ 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 from typing_extensions import Never -from _typeshed import StrPath - if sys.version_info >= (3, 11): from .abc import Traversable, TraversableResources