From 43fd43719ad1600610f71d1d03554ce0fb9d5013 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Mon, 8 Jul 2024 22:46:08 -0500 Subject: [PATCH 01/66] Update importlib resources for 3.13 --- stdlib/@tests/stubtest_allowlists/py313.txt | 10 ------ stdlib/importlib/resources/__init__.pyi | 34 ++++++++++++++++----- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/py313.txt b/stdlib/@tests/stubtest_allowlists/py313.txt index 5b0741b40dec..00e0e98238bb 100644 --- a/stdlib/@tests/stubtest_allowlists/py313.txt +++ b/stdlib/@tests/stubtest_allowlists/py313.txt @@ -9,16 +9,6 @@ _thread.start_joinable_thread _tkinter.create doctest.TestResults.__doc__ doctest.TestResults.__new__ -importlib.resources.Anchor -importlib.resources.Resource -importlib.resources.__all__ -importlib.resources.contents -importlib.resources.is_resource -importlib.resources.open_binary -importlib.resources.open_text -importlib.resources.path -importlib.resources.read_binary -importlib.resources.read_text os.path.splitroot # `__replace__` to be special cased in dataclasses pstats.FunctionProfile.__replace__ diff --git a/stdlib/importlib/resources/__init__.pyi b/stdlib/importlib/resources/__init__.pyi index 8d656563772c..f3f3aa8e0bd5 100644 --- a/stdlib/importlib/resources/__init__.pyi +++ b/stdlib/importlib/resources/__init__.pyi @@ -1,5 +1,6 @@ import os import sys +from _typeshed import StrPath from collections.abc import Iterator from contextlib import AbstractContextManager from pathlib import Path @@ -10,7 +11,7 @@ from typing_extensions import TypeAlias if sys.version_info >= (3, 9): from importlib.abc import Traversable -__all__ = ["Package", "Resource", "contents", "is_resource", "open_binary", "open_text", "path", "read_binary", "read_text"] +__all__ = ["Package", "contents", "is_resource", "open_binary", "open_text", "path", "read_binary", "read_text"] if sys.version_info >= (3, 9): __all__ += ["as_file", "files"] @@ -18,20 +19,37 @@ if sys.version_info >= (3, 9): if sys.version_info >= (3, 10): __all__ += ["ResourceReader"] +if sys.version_info >= (3, 13): + __all__ += ["Anchor"] +else: + __all__ += ["Resource"] + Package: TypeAlias = str | ModuleType +if sys.version_info >= (3, 12): + Anchor: TypeAlias = Package + if sys.version_info >= (3, 11): Resource: TypeAlias = str else: Resource: TypeAlias = str | os.PathLike[Any] -def open_binary(package: Package, resource: Resource) -> BinaryIO: ... -def open_text(package: Package, resource: Resource, encoding: str = "utf-8", errors: str = "strict") -> TextIO: ... -def read_binary(package: Package, resource: Resource) -> bytes: ... -def read_text(package: Package, resource: Resource, encoding: str = "utf-8", errors: str = "strict") -> str: ... -def path(package: Package, resource: Resource) -> AbstractContextManager[Path]: ... -def is_resource(package: Package, name: str) -> bool: ... -def contents(package: Package) -> Iterator[str]: ... +if sys.version_info >= (3, 13): + def open_binary(anchor: Anchor, *path_names: StrPath) -> BinaryIO: ... + def open_text(anchor: Anchor, *path_names: StrPath, encoding: str = ..., errors: str = "strict") -> TextIO: ... + def read_binary(anchor: Anchor, *path_names: StrPath) -> bytes: ... + def read_text(anchor: Anchor, *path_names: StrPath, encoding: str = ..., errors: str = "strict") -> str: ... + def path(anchor: Anchor, *path_names: StrPath) -> AbstractContextManager[Path]: ... + def is_resource(anchor: Anchor, *path_names: StrPath) -> bool: ... + def contents(anchor: Anchor, *path_names: StrPath) -> Iterator[str]: ... +else: + def open_binary(package: Package, resource: Resource) -> BinaryIO: ... + def open_text(package: Package, resource: Resource, encoding: str = "utf-8", errors: str = "strict") -> TextIO: ... + def read_binary(package: Package, resource: Resource) -> bytes: ... + def read_text(package: Package, resource: Resource, encoding: str = "utf-8", errors: str = "strict") -> str: ... + def path(package: Package, resource: Resource) -> AbstractContextManager[Path]: ... + def is_resource(package: Package, name: str) -> bool: ... + def contents(package: Package) -> Iterator[str]: ... if sys.version_info >= (3, 9): def as_file(path: Traversable) -> AbstractContextManager[Path]: ... From 90ea2f3237ad29c40d34fd70443cb71ff2e502ba Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 9 Jul 2024 03:48:07 +0000 Subject: [PATCH 02/66] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/importlib/resources/__init__.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/stdlib/importlib/resources/__init__.pyi b/stdlib/importlib/resources/__init__.pyi index f3f3aa8e0bd5..9c5fd01915f1 100644 --- a/stdlib/importlib/resources/__init__.pyi +++ b/stdlib/importlib/resources/__init__.pyi @@ -42,6 +42,7 @@ if sys.version_info >= (3, 13): def path(anchor: Anchor, *path_names: StrPath) -> AbstractContextManager[Path]: ... def is_resource(anchor: Anchor, *path_names: StrPath) -> bool: ... def contents(anchor: Anchor, *path_names: StrPath) -> Iterator[str]: ... + else: def open_binary(package: Package, resource: Resource) -> BinaryIO: ... def open_text(package: Package, resource: Resource, encoding: str = "utf-8", errors: str = "strict") -> TextIO: ... From e99fccaf773f27da7151dc0f05979833598514f6 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Mon, 8 Jul 2024 22:51:40 -0500 Subject: [PATCH 03/66] Fix --- stdlib/importlib/resources/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/importlib/resources/__init__.pyi b/stdlib/importlib/resources/__init__.pyi index 9c5fd01915f1..0f490e2e86ec 100644 --- a/stdlib/importlib/resources/__init__.pyi +++ b/stdlib/importlib/resources/__init__.pyi @@ -26,7 +26,7 @@ else: Package: TypeAlias = str | ModuleType -if sys.version_info >= (3, 12): +if sys.version_info >= (3, 13): Anchor: TypeAlias = Package if sys.version_info >= (3, 11): From 23e1544bebefa9aea814912c79194706bf3805f7 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Mon, 8 Jul 2024 22:55:06 -0500 Subject: [PATCH 04/66] Fix --- stdlib/importlib/resources/__init__.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/importlib/resources/__init__.pyi b/stdlib/importlib/resources/__init__.pyi index 0f490e2e86ec..ef55565cb719 100644 --- a/stdlib/importlib/resources/__init__.pyi +++ b/stdlib/importlib/resources/__init__.pyi @@ -29,9 +29,9 @@ Package: TypeAlias = str | ModuleType if sys.version_info >= (3, 13): Anchor: TypeAlias = Package -if sys.version_info >= (3, 11): +if sys.version_info < (3, 13): Resource: TypeAlias = str -else: +elif sys.version_info < (3, 11): Resource: TypeAlias = str | os.PathLike[Any] if sys.version_info >= (3, 13): From 14d6a765d10f8c76bfa457b76501ace62632f8f7 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Mon, 8 Jul 2024 23:00:04 -0500 Subject: [PATCH 05/66] Overloads --- stdlib/importlib/resources/__init__.pyi | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/stdlib/importlib/resources/__init__.pyi b/stdlib/importlib/resources/__init__.pyi index ef55565cb719..ca5a53e91296 100644 --- a/stdlib/importlib/resources/__init__.pyi +++ b/stdlib/importlib/resources/__init__.pyi @@ -5,7 +5,7 @@ from collections.abc import Iterator from contextlib import AbstractContextManager from pathlib import Path from types import ModuleType -from typing import Any, BinaryIO, TextIO +from typing import Any, BinaryIO, TextIO, overload from typing_extensions import TypeAlias if sys.version_info >= (3, 9): @@ -36,9 +36,15 @@ elif sys.version_info < (3, 11): if sys.version_info >= (3, 13): def open_binary(anchor: Anchor, *path_names: StrPath) -> BinaryIO: ... - def open_text(anchor: Anchor, *path_names: StrPath, encoding: str = ..., errors: str = "strict") -> TextIO: ... + @overload + def open_text(anchor: Anchor, path_name: StrPath, encoding: str = "utf-8", errors: str = "strict") -> TextIO: ... + @overload + def open_text(anchor: Anchor, *path_names: StrPath, encoding: str, errors: str = "strict") -> TextIO: ... def read_binary(anchor: Anchor, *path_names: StrPath) -> bytes: ... - def read_text(anchor: Anchor, *path_names: StrPath, encoding: str = ..., errors: str = "strict") -> str: ... + @overload + def read_text(anchor: Anchor, path_names: StrPath, encoding: str = "utf-8", errors: str = "strict") -> str: ... + @overload + def read_text(anchor: Anchor, *path_names: StrPath, encoding: str, errors: str = "strict") -> str: ... def path(anchor: Anchor, *path_names: StrPath) -> AbstractContextManager[Path]: ... def is_resource(anchor: Anchor, *path_names: StrPath) -> bool: ... def contents(anchor: Anchor, *path_names: StrPath) -> Iterator[str]: ... From ff35a20a19904b207fb12c26a224215ab75cb321 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Mon, 8 Jul 2024 23:00:22 -0500 Subject: [PATCH 06/66] Tweak --- stdlib/importlib/resources/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/importlib/resources/__init__.pyi b/stdlib/importlib/resources/__init__.pyi index ca5a53e91296..7bd351d6d983 100644 --- a/stdlib/importlib/resources/__init__.pyi +++ b/stdlib/importlib/resources/__init__.pyi @@ -37,7 +37,7 @@ elif sys.version_info < (3, 11): if sys.version_info >= (3, 13): def open_binary(anchor: Anchor, *path_names: StrPath) -> BinaryIO: ... @overload - def open_text(anchor: Anchor, path_name: StrPath, encoding: str = "utf-8", errors: str = "strict") -> TextIO: ... + def open_text(anchor: Anchor, path_names: StrPath, encoding: str = "utf-8", errors: str = "strict") -> TextIO: ... @overload def open_text(anchor: Anchor, *path_names: StrPath, encoding: str, errors: str = "strict") -> TextIO: ... def read_binary(anchor: Anchor, *path_names: StrPath) -> bytes: ... From d1230c327b535f99936adf902c2364a4f510b9dc Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Mon, 8 Jul 2024 23:01:45 -0500 Subject: [PATCH 07/66] Fix --- stdlib/importlib/resources/__init__.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/importlib/resources/__init__.pyi b/stdlib/importlib/resources/__init__.pyi index 7bd351d6d983..75bff2df33e9 100644 --- a/stdlib/importlib/resources/__init__.pyi +++ b/stdlib/importlib/resources/__init__.pyi @@ -37,12 +37,12 @@ elif sys.version_info < (3, 11): if sys.version_info >= (3, 13): def open_binary(anchor: Anchor, *path_names: StrPath) -> BinaryIO: ... @overload - def open_text(anchor: Anchor, path_names: StrPath, encoding: str = "utf-8", errors: str = "strict") -> TextIO: ... + def open_text(anchor: Anchor, *path_names: *tuple[StrPath], encoding: str = "utf-8", errors: str = "strict") -> TextIO: ... @overload def open_text(anchor: Anchor, *path_names: StrPath, encoding: str, errors: str = "strict") -> TextIO: ... def read_binary(anchor: Anchor, *path_names: StrPath) -> bytes: ... @overload - def read_text(anchor: Anchor, path_names: StrPath, encoding: str = "utf-8", errors: str = "strict") -> str: ... + def read_text(anchor: Anchor, *path_names: *tuple[StrPath], encoding: str = "utf-8", errors: str = "strict") -> str: ... @overload def read_text(anchor: Anchor, *path_names: StrPath, encoding: str, errors: str = "strict") -> str: ... def path(anchor: Anchor, *path_names: StrPath) -> AbstractContextManager[Path]: ... From ad24e2a84d1957b13f2c7adc5136a76a97e33592 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Mon, 8 Jul 2024 23:03:55 -0500 Subject: [PATCH 08/66] use unpack --- stdlib/importlib/resources/__init__.pyi | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/stdlib/importlib/resources/__init__.pyi b/stdlib/importlib/resources/__init__.pyi index 75bff2df33e9..ccf4f1abd6aa 100644 --- a/stdlib/importlib/resources/__init__.pyi +++ b/stdlib/importlib/resources/__init__.pyi @@ -6,7 +6,7 @@ from contextlib import AbstractContextManager from pathlib import Path from types import ModuleType from typing import Any, BinaryIO, TextIO, overload -from typing_extensions import TypeAlias +from typing_extensions import TypeAlias, Unpack if sys.version_info >= (3, 9): from importlib.abc import Traversable @@ -37,12 +37,16 @@ elif sys.version_info < (3, 11): if sys.version_info >= (3, 13): def open_binary(anchor: Anchor, *path_names: StrPath) -> BinaryIO: ... @overload - def open_text(anchor: Anchor, *path_names: *tuple[StrPath], encoding: str = "utf-8", errors: str = "strict") -> TextIO: ... + def open_text( + anchor: Anchor, *path_names: Unpack[tuple[StrPath]], encoding: str = "utf-8", errors: str = "strict" + ) -> TextIO: ... @overload def open_text(anchor: Anchor, *path_names: StrPath, encoding: str, errors: str = "strict") -> TextIO: ... def read_binary(anchor: Anchor, *path_names: StrPath) -> bytes: ... @overload - def read_text(anchor: Anchor, *path_names: *tuple[StrPath], encoding: str = "utf-8", errors: str = "strict") -> str: ... + def read_text( + anchor: Anchor, *path_names: Unpack[tuple[StrPath]], encoding: str = "utf-8", errors: str = "strict" + ) -> str: ... @overload def read_text(anchor: Anchor, *path_names: StrPath, encoding: str, errors: str = "strict") -> str: ... def path(anchor: Anchor, *path_names: StrPath) -> AbstractContextManager[Path]: ... From 4d1dfca791bf6ae2b4daf1f893644c8096a96fe0 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Mon, 8 Jul 2024 23:09:14 -0500 Subject: [PATCH 09/66] Add tests --- .../test_cases/check_importlib_resources.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 stdlib/@tests/test_cases/check_importlib_resources.py diff --git a/stdlib/@tests/test_cases/check_importlib_resources.py b/stdlib/@tests/test_cases/check_importlib_resources.py new file mode 100644 index 000000000000..f983227f2c72 --- /dev/null +++ b/stdlib/@tests/test_cases/check_importlib_resources.py @@ -0,0 +1,33 @@ +import sys +import importlib.resources +import pathlib + + +class _CustomPathLike: + def __init__(self, path: str) -> None: + self.path = path + + def __fspath__(self) -> str: + return self.path + + +if sys.version_info >= (3, 13): + + def f(pth: pathlib.Path | str | _CustomPathLike) -> None: + importlib.resources.open_binary("pkg", pth) + # Encoding defaults to "utf-8" for one arg. + importlib.resources.open_text("pkg", pth) + # Otherwise, it must be specified. + importlib.resources.open_text("pkg", pth, pth) # type: ignore + importlib.resources.open_text("pkg", pth, pth, encoding="utf-8") + + # Encoding defaults to "utf-8" for one arg. + importlib.resources.read_text("pkg", pth) + # Otherwise, it must be specified. + importlib.resources.read_text("pkg", pth, pth) # type: ignore + importlib.resources.read_text("pkg", pth, pth, encoding="utf-8") + + importlib.resources.read_binary("pkg", pth) + importlib.resources.path("pkg", pth) + importlib.resources.is_resource("pkg", pth) + importlib.resources.contents("pkg", pth) From 90f1f349cc9fd7dbf7e89421f3c15db80be9f65f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 9 Jul 2024 04:10:53 +0000 Subject: [PATCH 10/66] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/@tests/test_cases/check_importlib_resources.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stdlib/@tests/test_cases/check_importlib_resources.py b/stdlib/@tests/test_cases/check_importlib_resources.py index f983227f2c72..c0f6fb0700a1 100644 --- a/stdlib/@tests/test_cases/check_importlib_resources.py +++ b/stdlib/@tests/test_cases/check_importlib_resources.py @@ -1,6 +1,8 @@ -import sys +from __future__ import annotations + import importlib.resources import pathlib +import sys class _CustomPathLike: From bac332eff0caf8cb2087df22c8f6b5b835d55248 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Mon, 8 Jul 2024 23:12:32 -0500 Subject: [PATCH 11/66] All nullable --- stdlib/importlib/resources/__init__.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stdlib/importlib/resources/__init__.pyi b/stdlib/importlib/resources/__init__.pyi index ccf4f1abd6aa..75ac5b77c784 100644 --- a/stdlib/importlib/resources/__init__.pyi +++ b/stdlib/importlib/resources/__init__.pyi @@ -38,17 +38,17 @@ if sys.version_info >= (3, 13): def open_binary(anchor: Anchor, *path_names: StrPath) -> BinaryIO: ... @overload def open_text( - anchor: Anchor, *path_names: Unpack[tuple[StrPath]], encoding: str = "utf-8", errors: str = "strict" + anchor: Anchor, *path_names: Unpack[tuple[StrPath]], encoding: str | None = "utf-8", errors: str | None = "strict" ) -> TextIO: ... @overload - def open_text(anchor: Anchor, *path_names: StrPath, encoding: str, errors: str = "strict") -> TextIO: ... + def open_text(anchor: Anchor, *path_names: StrPath, encoding: str | None, errors: str | None = "strict") -> TextIO: ... def read_binary(anchor: Anchor, *path_names: StrPath) -> bytes: ... @overload def read_text( - anchor: Anchor, *path_names: Unpack[tuple[StrPath]], encoding: str = "utf-8", errors: str = "strict" + anchor: Anchor, *path_names: Unpack[tuple[StrPath]], encoding: str | None = "utf-8", errors: str | None = "strict" ) -> str: ... @overload - def read_text(anchor: Anchor, *path_names: StrPath, encoding: str, errors: str = "strict") -> str: ... + def read_text(anchor: Anchor, *path_names: StrPath, encoding: str | None, errors: str | None = "strict") -> str: ... def path(anchor: Anchor, *path_names: StrPath) -> AbstractContextManager[Path]: ... def is_resource(anchor: Anchor, *path_names: StrPath) -> bool: ... def contents(anchor: Anchor, *path_names: StrPath) -> Iterator[str]: ... From ae8bbe08b920face0a313d790a852fc10110722a Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Mon, 8 Jul 2024 23:16:58 -0500 Subject: [PATCH 12/66] Tweak --- stdlib/importlib/resources/__init__.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/importlib/resources/__init__.pyi b/stdlib/importlib/resources/__init__.pyi index 75ac5b77c784..28fa5309af9e 100644 --- a/stdlib/importlib/resources/__init__.pyi +++ b/stdlib/importlib/resources/__init__.pyi @@ -1,3 +1,4 @@ +from io import TextIOWrapper import os import sys from _typeshed import StrPath @@ -39,7 +40,7 @@ if sys.version_info >= (3, 13): @overload def open_text( anchor: Anchor, *path_names: Unpack[tuple[StrPath]], encoding: str | None = "utf-8", errors: str | None = "strict" - ) -> TextIO: ... + ) -> TextIOWrapper: ... @overload def open_text(anchor: Anchor, *path_names: StrPath, encoding: str | None, errors: str | None = "strict") -> TextIO: ... def read_binary(anchor: Anchor, *path_names: StrPath) -> bytes: ... From cc428aa80ac372e598f00caa298601d024b67e0d Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Mon, 8 Jul 2024 23:17:20 -0500 Subject: [PATCH 13/66] Tweak --- stdlib/importlib/resources/__init__.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/importlib/resources/__init__.pyi b/stdlib/importlib/resources/__init__.pyi index 28fa5309af9e..0331d142cdf0 100644 --- a/stdlib/importlib/resources/__init__.pyi +++ b/stdlib/importlib/resources/__init__.pyi @@ -1,9 +1,9 @@ -from io import TextIOWrapper import os import sys from _typeshed import StrPath from collections.abc import Iterator from contextlib import AbstractContextManager +from io import TextIOWrapper from pathlib import Path from types import ModuleType from typing import Any, BinaryIO, TextIO, overload @@ -42,7 +42,7 @@ if sys.version_info >= (3, 13): anchor: Anchor, *path_names: Unpack[tuple[StrPath]], encoding: str | None = "utf-8", errors: str | None = "strict" ) -> TextIOWrapper: ... @overload - def open_text(anchor: Anchor, *path_names: StrPath, encoding: str | None, errors: str | None = "strict") -> TextIO: ... + def open_text(anchor: Anchor, *path_names: StrPath, encoding: str | None, errors: str | None = "strict") -> TextIOWrapper: ... def read_binary(anchor: Anchor, *path_names: StrPath) -> bytes: ... @overload def read_text( From 55e1c525dff2baaa9a17b1d07a7fddd6cea359f7 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Mon, 8 Jul 2024 23:22:27 -0500 Subject: [PATCH 14/66] Fix --- stdlib/importlib/resources/__init__.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/importlib/resources/__init__.pyi b/stdlib/importlib/resources/__init__.pyi index 0331d142cdf0..f8dadf3c7d77 100644 --- a/stdlib/importlib/resources/__init__.pyi +++ b/stdlib/importlib/resources/__init__.pyi @@ -30,10 +30,10 @@ Package: TypeAlias = str | ModuleType if sys.version_info >= (3, 13): Anchor: TypeAlias = Package -if sys.version_info < (3, 13): - Resource: TypeAlias = str -elif sys.version_info < (3, 11): +if sys.version_info < (3, 11): Resource: TypeAlias = str | os.PathLike[Any] +elif sys.version_info < (3, 13): + Resource: TypeAlias = str if sys.version_info >= (3, 13): def open_binary(anchor: Anchor, *path_names: StrPath) -> BinaryIO: ... From f262d0a8eb2a76334bfa5c758ae7f5ecf92b432a Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Thu, 11 Jul 2024 10:47:28 -0500 Subject: [PATCH 15/66] Move to _common --- stdlib/importlib/resources/__init__.pyi | 9 +++------ stdlib/importlib/resources/_common.pyi | 8 ++++++++ 2 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 stdlib/importlib/resources/_common.pyi diff --git a/stdlib/importlib/resources/__init__.pyi b/stdlib/importlib/resources/__init__.pyi index f8dadf3c7d77..406a345bc479 100644 --- a/stdlib/importlib/resources/__init__.pyi +++ b/stdlib/importlib/resources/__init__.pyi @@ -3,9 +3,9 @@ import sys from _typeshed import StrPath from collections.abc import Iterator from contextlib import AbstractContextManager +from importlib.resources._common import Package from io import TextIOWrapper from pathlib import Path -from types import ModuleType from typing import Any, BinaryIO, TextIO, overload from typing_extensions import TypeAlias, Unpack @@ -21,15 +21,12 @@ if sys.version_info >= (3, 10): __all__ += ["ResourceReader"] if sys.version_info >= (3, 13): + from importlib.resources._common import Anchor + __all__ += ["Anchor"] else: __all__ += ["Resource"] -Package: TypeAlias = str | ModuleType - -if sys.version_info >= (3, 13): - Anchor: TypeAlias = Package - if sys.version_info < (3, 11): Resource: TypeAlias = str | os.PathLike[Any] elif sys.version_info < (3, 13): diff --git a/stdlib/importlib/resources/_common.pyi b/stdlib/importlib/resources/_common.pyi new file mode 100644 index 000000000000..df1ce00881a6 --- /dev/null +++ b/stdlib/importlib/resources/_common.pyi @@ -0,0 +1,8 @@ +import sys +from types import ModuleType +from typing import TypeAlias + +Package: TypeAlias = str | ModuleType + +if sys.version_info >= (3, 13): + Anchor: TypeAlias = Package From f91ed1e316b5e44828e1bfecfbed1d187af562ca Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Thu, 11 Jul 2024 10:47:56 -0500 Subject: [PATCH 16/66] Use TS --- stdlib/importlib/resources/_common.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/importlib/resources/_common.pyi b/stdlib/importlib/resources/_common.pyi index df1ce00881a6..18520fbae907 100644 --- a/stdlib/importlib/resources/_common.pyi +++ b/stdlib/importlib/resources/_common.pyi @@ -1,6 +1,6 @@ import sys from types import ModuleType -from typing import TypeAlias +from typing_extensions import TypeAlias Package: TypeAlias = str | ModuleType From 5d9a9b4b9305c9111bd2f8802c90a70b9acc8e78 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Thu, 11 Jul 2024 11:30:33 -0500 Subject: [PATCH 17/66] Address comment --- stdlib/VERSIONS | 1 + stdlib/importlib/resources/__init__.pyi | 4 +++- stdlib/importlib/resources/_common.pyi | 4 +--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/stdlib/VERSIONS b/stdlib/VERSIONS index 641f951ce3c0..1c2c6ef54169 100644 --- a/stdlib/VERSIONS +++ b/stdlib/VERSIONS @@ -162,6 +162,7 @@ importlib.metadata.diagnose: 3.13- importlib.readers: 3.10- importlib.resources: 3.7- importlib.resources.abc: 3.11- +importlib.resources._common: 3.11- importlib.resources.readers: 3.11- importlib.resources.simple: 3.11- importlib.simple: 3.11- diff --git a/stdlib/importlib/resources/__init__.pyi b/stdlib/importlib/resources/__init__.pyi index 406a345bc479..ebebae10fae2 100644 --- a/stdlib/importlib/resources/__init__.pyi +++ b/stdlib/importlib/resources/__init__.pyi @@ -3,12 +3,14 @@ import sys from _typeshed import StrPath from collections.abc import Iterator from contextlib import AbstractContextManager -from importlib.resources._common import Package from io import TextIOWrapper from pathlib import Path +from types import ModuleType from typing import Any, BinaryIO, TextIO, overload from typing_extensions import TypeAlias, Unpack +Package: TypeAlias = str | ModuleType + if sys.version_info >= (3, 9): from importlib.abc import Traversable diff --git a/stdlib/importlib/resources/_common.pyi b/stdlib/importlib/resources/_common.pyi index 18520fbae907..8f44724cc2cb 100644 --- a/stdlib/importlib/resources/_common.pyi +++ b/stdlib/importlib/resources/_common.pyi @@ -1,8 +1,6 @@ import sys -from types import ModuleType +from importlib.resources import Package from typing_extensions import TypeAlias -Package: TypeAlias = str | ModuleType - if sys.version_info >= (3, 13): Anchor: TypeAlias = Package From f4cb5863ea19cdfdd2914f99d1bfab81fbb87b66 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Thu, 11 Jul 2024 11:32:23 -0500 Subject: [PATCH 18/66] Fix --- stdlib/importlib/resources/__init__.pyi | 4 +--- stdlib/importlib/resources/_common.pyi | 4 +++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/stdlib/importlib/resources/__init__.pyi b/stdlib/importlib/resources/__init__.pyi index ebebae10fae2..406a345bc479 100644 --- a/stdlib/importlib/resources/__init__.pyi +++ b/stdlib/importlib/resources/__init__.pyi @@ -3,14 +3,12 @@ import sys from _typeshed import StrPath from collections.abc import Iterator from contextlib import AbstractContextManager +from importlib.resources._common import Package from io import TextIOWrapper from pathlib import Path -from types import ModuleType from typing import Any, BinaryIO, TextIO, overload from typing_extensions import TypeAlias, Unpack -Package: TypeAlias = str | ModuleType - if sys.version_info >= (3, 9): from importlib.abc import Traversable diff --git a/stdlib/importlib/resources/_common.pyi b/stdlib/importlib/resources/_common.pyi index 8f44724cc2cb..18520fbae907 100644 --- a/stdlib/importlib/resources/_common.pyi +++ b/stdlib/importlib/resources/_common.pyi @@ -1,6 +1,8 @@ import sys -from importlib.resources import Package +from types import ModuleType from typing_extensions import TypeAlias +Package: TypeAlias = str | ModuleType + if sys.version_info >= (3, 13): Anchor: TypeAlias = Package From ad92305d85fc070359945901b2bde67bd08762eb Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Thu, 11 Jul 2024 11:34:32 -0500 Subject: [PATCH 19/66] tweak again --- stdlib/importlib/resources/__init__.pyi | 4 +++- stdlib/importlib/resources/_common.pyi | 4 +--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/stdlib/importlib/resources/__init__.pyi b/stdlib/importlib/resources/__init__.pyi index 406a345bc479..ebebae10fae2 100644 --- a/stdlib/importlib/resources/__init__.pyi +++ b/stdlib/importlib/resources/__init__.pyi @@ -3,12 +3,14 @@ import sys from _typeshed import StrPath from collections.abc import Iterator from contextlib import AbstractContextManager -from importlib.resources._common import Package from io import TextIOWrapper from pathlib import Path +from types import ModuleType from typing import Any, BinaryIO, TextIO, overload from typing_extensions import TypeAlias, Unpack +Package: TypeAlias = str | ModuleType + if sys.version_info >= (3, 9): from importlib.abc import Traversable diff --git a/stdlib/importlib/resources/_common.pyi b/stdlib/importlib/resources/_common.pyi index 18520fbae907..8f44724cc2cb 100644 --- a/stdlib/importlib/resources/_common.pyi +++ b/stdlib/importlib/resources/_common.pyi @@ -1,8 +1,6 @@ import sys -from types import ModuleType +from importlib.resources import Package from typing_extensions import TypeAlias -Package: TypeAlias = str | ModuleType - if sys.version_info >= (3, 13): Anchor: TypeAlias = Package From c44c71ba81fdfcf36efa59cc88080f4bee70aaa0 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Thu, 11 Jul 2024 11:35:24 -0500 Subject: [PATCH 20/66] reorder --- stdlib/VERSIONS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/VERSIONS b/stdlib/VERSIONS index 1c2c6ef54169..13ac9bfd195f 100644 --- a/stdlib/VERSIONS +++ b/stdlib/VERSIONS @@ -161,8 +161,8 @@ importlib.metadata._meta: 3.10- importlib.metadata.diagnose: 3.13- importlib.readers: 3.10- importlib.resources: 3.7- -importlib.resources.abc: 3.11- importlib.resources._common: 3.11- +importlib.resources.abc: 3.11- importlib.resources.readers: 3.11- importlib.resources.simple: 3.11- importlib.simple: 3.11- From 9c3100816d7b95916eeb6b4066d18922ff7c0de6 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Thu, 11 Jul 2024 11:38:17 -0500 Subject: [PATCH 21/66] Tweak --- stdlib/importlib/resources/__init__.pyi | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/stdlib/importlib/resources/__init__.pyi b/stdlib/importlib/resources/__init__.pyi index ebebae10fae2..b185a72ce719 100644 --- a/stdlib/importlib/resources/__init__.pyi +++ b/stdlib/importlib/resources/__init__.pyi @@ -22,11 +22,7 @@ if sys.version_info >= (3, 9): if sys.version_info >= (3, 10): __all__ += ["ResourceReader"] -if sys.version_info >= (3, 13): - from importlib.resources._common import Anchor - - __all__ += ["Anchor"] -else: +if sys.version_info < (3, 13): __all__ += ["Resource"] if sys.version_info < (3, 11): @@ -35,6 +31,10 @@ elif sys.version_info < (3, 13): Resource: TypeAlias = str if sys.version_info >= (3, 13): + from importlib.resources._common import Anchor + + __all__ += ["Anchor"] + def open_binary(anchor: Anchor, *path_names: StrPath) -> BinaryIO: ... @overload def open_text( From bafcf5178f683fb79ebf4bec666c3b6e694d55e1 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Sat, 13 Jul 2024 11:13:58 -0500 Subject: [PATCH 22/66] Resolve issues --- stdlib/importlib/resources/__init__.pyi | 13 ++++++--- stdlib/importlib/resources/_common.pyi | 38 +++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/stdlib/importlib/resources/__init__.pyi b/stdlib/importlib/resources/__init__.pyi index b185a72ce719..6b31457663a2 100644 --- a/stdlib/importlib/resources/__init__.pyi +++ b/stdlib/importlib/resources/__init__.pyi @@ -9,7 +9,10 @@ from types import ModuleType from typing import Any, BinaryIO, TextIO, overload from typing_extensions import TypeAlias, Unpack -Package: TypeAlias = str | ModuleType +if sys.version_info >= (3, 11): + from importlib.resources._common import Package +else: + Package: TypeAlias = str | ModuleType if sys.version_info >= (3, 9): from importlib.abc import Traversable @@ -62,11 +65,13 @@ else: def is_resource(package: Package, name: str) -> bool: ... def contents(package: Package) -> Iterator[str]: ... -if sys.version_info >= (3, 9): +if sys.version_info >= (3, 11): + from importlib.resources._common import as_file +elif sys.version_info >= (3, 9): def as_file(path: Traversable) -> AbstractContextManager[Path]: ... -if sys.version_info >= (3, 12): - def files(anchor: Package | None = ...) -> Traversable: ... +if sys.version_info >= (3, 11): + from importlib.resources._common import files elif sys.version_info >= (3, 9): def files(package: Package) -> Traversable: ... diff --git a/stdlib/importlib/resources/_common.pyi b/stdlib/importlib/resources/_common.pyi index 8f44724cc2cb..072fba3cc8da 100644 --- a/stdlib/importlib/resources/_common.pyi +++ b/stdlib/importlib/resources/_common.pyi @@ -1,6 +1,40 @@ import sys -from importlib.resources import Package +import types +from contextlib import AbstractContextManager +from importlib.abc import ResourceReader, Traversable +from pathlib import Path +from typing import Callable, overload from typing_extensions import TypeAlias +from warnings import deprecated -if sys.version_info >= (3, 13): +Package: TypeAlias = str | types.ModuleType + +if sys.version_info >= (3, 12): Anchor: TypeAlias = Package + +if sys.version_info >= (3, 12): + def package_to_anchor( + package_to_anchor: Callable[[Anchor | None], Traversable], + ) -> Callable[[Anchor | None, Anchor | None], Traversable]: ... + +if sys.version_info >= (3, 12): + @overload + @deprecated("First parameter to files is renamed to 'anchor'") + def files(package: Anchor | None = None) -> Traversable: ... + @overload + def files(anchor: Anchor | None = None) -> Traversable: ... +else: + def files(package: Package) -> Traversable: ... + +def get_resource_reader(package: types.ModuleType) -> ResourceReader | None: ... + +if sys.version_info >= (3, 12): + def resolve(cand: Anchor | None) -> types.ModuleType: ... +else: + def resolve(cand: Package) -> types.ModuleType: ... + +if sys.version_info < (3, 12): + def get_package(package: Package) -> types.ModuleType: ... + +def from_package(package: types.ModuleType) -> Traversable: ... +def as_file(path: Traversable) -> AbstractContextManager[Path]: ... From f271829a4823c010955da21116ded90be9be6f38 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Sat, 13 Jul 2024 11:18:02 -0500 Subject: [PATCH 23/66] Move to functional --- stdlib/VERSIONS | 1 + stdlib/importlib/resources/__init__.pyi | 18 +-------------- stdlib/importlib/resources/_functional.pyi | 26 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 17 deletions(-) create mode 100644 stdlib/importlib/resources/_functional.pyi diff --git a/stdlib/VERSIONS b/stdlib/VERSIONS index 13ac9bfd195f..cbce812c402b 100644 --- a/stdlib/VERSIONS +++ b/stdlib/VERSIONS @@ -162,6 +162,7 @@ importlib.metadata.diagnose: 3.13- importlib.readers: 3.10- importlib.resources: 3.7- importlib.resources._common: 3.11- +importlib.resources._functional: 3.13- importlib.resources.abc: 3.11- importlib.resources.readers: 3.11- importlib.resources.simple: 3.11- diff --git a/stdlib/importlib/resources/__init__.pyi b/stdlib/importlib/resources/__init__.pyi index 6b31457663a2..9a38b841b09d 100644 --- a/stdlib/importlib/resources/__init__.pyi +++ b/stdlib/importlib/resources/__init__.pyi @@ -38,23 +38,7 @@ if sys.version_info >= (3, 13): __all__ += ["Anchor"] - def open_binary(anchor: Anchor, *path_names: StrPath) -> BinaryIO: ... - @overload - def open_text( - anchor: Anchor, *path_names: Unpack[tuple[StrPath]], encoding: str | None = "utf-8", errors: str | None = "strict" - ) -> TextIOWrapper: ... - @overload - def open_text(anchor: Anchor, *path_names: StrPath, encoding: str | None, errors: str | None = "strict") -> TextIOWrapper: ... - def read_binary(anchor: Anchor, *path_names: StrPath) -> bytes: ... - @overload - def read_text( - anchor: Anchor, *path_names: Unpack[tuple[StrPath]], encoding: str | None = "utf-8", errors: str | None = "strict" - ) -> str: ... - @overload - def read_text(anchor: Anchor, *path_names: StrPath, encoding: str | None, errors: str | None = "strict") -> str: ... - def path(anchor: Anchor, *path_names: StrPath) -> AbstractContextManager[Path]: ... - def is_resource(anchor: Anchor, *path_names: StrPath) -> bool: ... - def contents(anchor: Anchor, *path_names: StrPath) -> Iterator[str]: ... + from importlib.resources._functional import contents, is_resource, open_binary, open_text, path, read_binary, read_text else: def open_binary(package: Package, resource: Resource) -> BinaryIO: ... diff --git a/stdlib/importlib/resources/_functional.pyi b/stdlib/importlib/resources/_functional.pyi new file mode 100644 index 000000000000..b0c1a74d5dcd --- /dev/null +++ b/stdlib/importlib/resources/_functional.pyi @@ -0,0 +1,26 @@ +from _typeshed import StrPath +from collections.abc import Iterator +from contextlib import AbstractContextManager +from importlib.resources._common import Anchor +from io import TextIOWrapper +from pathlib import Path +from typing import BinaryIO, overload +from typing_extensions import Unpack + +def open_binary(anchor: Anchor, *path_names: StrPath) -> BinaryIO: ... +@overload +def open_text( + anchor: Anchor, *path_names: Unpack[tuple[StrPath]], encoding: str | None = "utf-8", errors: str | None = "strict" +) -> TextIOWrapper: ... +@overload +def open_text(anchor: Anchor, *path_names: StrPath, encoding: str | None, errors: str | None = "strict") -> TextIOWrapper: ... +def read_binary(anchor: Anchor, *path_names: StrPath) -> bytes: ... +@overload +def read_text( + anchor: Anchor, *path_names: Unpack[tuple[StrPath]], encoding: str | None = "utf-8", errors: str | None = "strict" +) -> str: ... +@overload +def read_text(anchor: Anchor, *path_names: StrPath, encoding: str | None, errors: str | None = "strict") -> str: ... +def path(anchor: Anchor, *path_names: StrPath) -> AbstractContextManager[Path]: ... +def is_resource(anchor: Anchor, *path_names: StrPath) -> bool: ... +def contents(anchor: Anchor, *path_names: StrPath) -> Iterator[str]: ... From 201ba163c4e2880ea2d823238eef5abb238532b8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 13 Jul 2024 16:22:16 +0000 Subject: [PATCH 24/66] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/importlib/resources/__init__.pyi | 6 ++---- stdlib/importlib/resources/_common.pyi | 4 +++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/stdlib/importlib/resources/__init__.pyi b/stdlib/importlib/resources/__init__.pyi index 9a38b841b09d..f5628b94ec25 100644 --- a/stdlib/importlib/resources/__init__.pyi +++ b/stdlib/importlib/resources/__init__.pyi @@ -1,13 +1,11 @@ import os import sys -from _typeshed import StrPath from collections.abc import Iterator from contextlib import AbstractContextManager -from io import TextIOWrapper from pathlib import Path from types import ModuleType -from typing import Any, BinaryIO, TextIO, overload -from typing_extensions import TypeAlias, Unpack +from typing import Any, BinaryIO, TextIO +from typing_extensions import TypeAlias if sys.version_info >= (3, 11): from importlib.resources._common import Package diff --git a/stdlib/importlib/resources/_common.pyi b/stdlib/importlib/resources/_common.pyi index 072fba3cc8da..a7b60c996c2c 100644 --- a/stdlib/importlib/resources/_common.pyi +++ b/stdlib/importlib/resources/_common.pyi @@ -14,7 +14,7 @@ if sys.version_info >= (3, 12): if sys.version_info >= (3, 12): def package_to_anchor( - package_to_anchor: Callable[[Anchor | None], Traversable], + package_to_anchor: Callable[[Anchor | None], Traversable] ) -> Callable[[Anchor | None, Anchor | None], Traversable]: ... if sys.version_info >= (3, 12): @@ -23,6 +23,7 @@ if sys.version_info >= (3, 12): def files(package: Anchor | None = None) -> Traversable: ... @overload def files(anchor: Anchor | None = None) -> Traversable: ... + else: def files(package: Package) -> Traversable: ... @@ -30,6 +31,7 @@ def get_resource_reader(package: types.ModuleType) -> ResourceReader | None: ... if sys.version_info >= (3, 12): def resolve(cand: Anchor | None) -> types.ModuleType: ... + else: def resolve(cand: Package) -> types.ModuleType: ... From 7d46617a5282b51eaa720cf211d017fd9711e970 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Sat, 13 Jul 2024 11:24:20 -0500 Subject: [PATCH 25/66] Fix --- stdlib/importlib/resources/_common.pyi | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/stdlib/importlib/resources/_common.pyi b/stdlib/importlib/resources/_common.pyi index a7b60c996c2c..8452b006934a 100644 --- a/stdlib/importlib/resources/_common.pyi +++ b/stdlib/importlib/resources/_common.pyi @@ -4,8 +4,7 @@ from contextlib import AbstractContextManager from importlib.abc import ResourceReader, Traversable from pathlib import Path from typing import Callable, overload -from typing_extensions import TypeAlias -from warnings import deprecated +from typing_extensions import TypeAlias, deprecated Package: TypeAlias = str | types.ModuleType @@ -14,7 +13,7 @@ if sys.version_info >= (3, 12): if sys.version_info >= (3, 12): def package_to_anchor( - package_to_anchor: Callable[[Anchor | None], Traversable] + package_to_anchor: Callable[[Anchor | None], Traversable], ) -> Callable[[Anchor | None, Anchor | None], Traversable]: ... if sys.version_info >= (3, 12): From 52dfac22a7e1c3eab88621b38f63b900e6c2838d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 13 Jul 2024 16:25:58 +0000 Subject: [PATCH 26/66] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/importlib/resources/_common.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/importlib/resources/_common.pyi b/stdlib/importlib/resources/_common.pyi index 8452b006934a..521185074f44 100644 --- a/stdlib/importlib/resources/_common.pyi +++ b/stdlib/importlib/resources/_common.pyi @@ -13,7 +13,7 @@ if sys.version_info >= (3, 12): if sys.version_info >= (3, 12): def package_to_anchor( - package_to_anchor: Callable[[Anchor | None], Traversable], + package_to_anchor: Callable[[Anchor | None], Traversable] ) -> Callable[[Anchor | None, Anchor | None], Traversable]: ... if sys.version_info >= (3, 12): From 0af767dbdf970010e653bf68c2bfb7e594b560f2 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Sat, 13 Jul 2024 11:31:22 -0500 Subject: [PATCH 27/66] tweak --- stdlib/importlib/resources/_common.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/importlib/resources/_common.pyi b/stdlib/importlib/resources/_common.pyi index 521185074f44..2a5735bb5e0c 100644 --- a/stdlib/importlib/resources/_common.pyi +++ b/stdlib/importlib/resources/_common.pyi @@ -17,11 +17,11 @@ if sys.version_info >= (3, 12): ) -> Callable[[Anchor | None, Anchor | None], Traversable]: ... if sys.version_info >= (3, 12): + @overload + def files(anchor: Anchor | None = None) -> Traversable: ... @overload @deprecated("First parameter to files is renamed to 'anchor'") def files(package: Anchor | None = None) -> Traversable: ... - @overload - def files(anchor: Anchor | None = None) -> Traversable: ... else: def files(package: Package) -> Traversable: ... From af74ee9cf403503d9f977a31aed5cfbaf789c0ee Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Sat, 13 Jul 2024 11:35:23 -0500 Subject: [PATCH 28/66] Tweak --- stdlib/importlib/resources/_common.pyi | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/stdlib/importlib/resources/_common.pyi b/stdlib/importlib/resources/_common.pyi index 2a5735bb5e0c..1532e129a22a 100644 --- a/stdlib/importlib/resources/_common.pyi +++ b/stdlib/importlib/resources/_common.pyi @@ -11,12 +11,9 @@ Package: TypeAlias = str | types.ModuleType if sys.version_info >= (3, 12): Anchor: TypeAlias = Package -if sys.version_info >= (3, 12): def package_to_anchor( - package_to_anchor: Callable[[Anchor | None], Traversable] + package_to_anchor: Callable[[Anchor | None], Traversable], ) -> Callable[[Anchor | None, Anchor | None], Traversable]: ... - -if sys.version_info >= (3, 12): @overload def files(anchor: Anchor | None = None) -> Traversable: ... @overload From d23df9749c1f9f164db0772c178d3c1c3ff1a31e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 13 Jul 2024 16:37:00 +0000 Subject: [PATCH 29/66] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/importlib/resources/_common.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/importlib/resources/_common.pyi b/stdlib/importlib/resources/_common.pyi index 1532e129a22a..a8618ebdb6a3 100644 --- a/stdlib/importlib/resources/_common.pyi +++ b/stdlib/importlib/resources/_common.pyi @@ -12,7 +12,7 @@ if sys.version_info >= (3, 12): Anchor: TypeAlias = Package def package_to_anchor( - package_to_anchor: Callable[[Anchor | None], Traversable], + package_to_anchor: Callable[[Anchor | None], Traversable] ) -> Callable[[Anchor | None, Anchor | None], Traversable]: ... @overload def files(anchor: Anchor | None = None) -> Traversable: ... From 8e516d63406a728220c1f462df9c38b3b6b76cd6 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Sat, 13 Jul 2024 11:52:25 -0500 Subject: [PATCH 30/66] Tweak --- stdlib/importlib/resources/_functional.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/importlib/resources/_functional.pyi b/stdlib/importlib/resources/_functional.pyi index b0c1a74d5dcd..6a3e8c795ccd 100644 --- a/stdlib/importlib/resources/_functional.pyi +++ b/stdlib/importlib/resources/_functional.pyi @@ -1,7 +1,7 @@ from _typeshed import StrPath from collections.abc import Iterator from contextlib import AbstractContextManager -from importlib.resources._common import Anchor +from importlib.resources import Anchor from io import TextIOWrapper from pathlib import Path from typing import BinaryIO, overload From 49828afc1f61d14526aa73a0d2c5c481af9cedf5 Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Mon, 15 Jul 2024 21:25:11 -0500 Subject: [PATCH 31/66] Update stdlib/importlib/resources/__init__.pyi Co-authored-by: Sebastian Rittau --- stdlib/importlib/resources/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/importlib/resources/__init__.pyi b/stdlib/importlib/resources/__init__.pyi index f5628b94ec25..555610eaa6dd 100644 --- a/stdlib/importlib/resources/__init__.pyi +++ b/stdlib/importlib/resources/__init__.pyi @@ -32,7 +32,7 @@ elif sys.version_info < (3, 13): Resource: TypeAlias = str if sys.version_info >= (3, 13): - from importlib.resources._common import Anchor + from importlib.resources._common import Anchor as Anchor __all__ += ["Anchor"] From d34c137bc34db643e4d2d157065a21bd084c9962 Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Mon, 15 Jul 2024 21:26:13 -0500 Subject: [PATCH 32/66] Update stdlib/importlib/resources/_functional.pyi Co-authored-by: Sebastian Rittau --- stdlib/importlib/resources/_functional.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/importlib/resources/_functional.pyi b/stdlib/importlib/resources/_functional.pyi index 6a3e8c795ccd..b0c1a74d5dcd 100644 --- a/stdlib/importlib/resources/_functional.pyi +++ b/stdlib/importlib/resources/_functional.pyi @@ -1,7 +1,7 @@ from _typeshed import StrPath from collections.abc import Iterator from contextlib import AbstractContextManager -from importlib.resources import Anchor +from importlib.resources._common import Anchor from io import TextIOWrapper from pathlib import Path from typing import BinaryIO, overload From c4dc73f8f399df5238910426a04831f342bd39ed Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Mon, 15 Jul 2024 21:33:53 -0500 Subject: [PATCH 33/66] Add --- stdlib/importlib/resources/_common.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/importlib/resources/_common.pyi b/stdlib/importlib/resources/_common.pyi index a8618ebdb6a3..35848cdf9f59 100644 --- a/stdlib/importlib/resources/_common.pyi +++ b/stdlib/importlib/resources/_common.pyi @@ -12,7 +12,7 @@ if sys.version_info >= (3, 12): Anchor: TypeAlias = Package def package_to_anchor( - package_to_anchor: Callable[[Anchor | None], Traversable] + func: Callable[[Anchor | None], Traversable], ) -> Callable[[Anchor | None, Anchor | None], Traversable]: ... @overload def files(anchor: Anchor | None = None) -> Traversable: ... From 36a5efc44c34abf1201c4b0503431aab8c64ff1e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 16 Jul 2024 02:36:24 +0000 Subject: [PATCH 34/66] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/importlib/resources/_common.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/importlib/resources/_common.pyi b/stdlib/importlib/resources/_common.pyi index 35848cdf9f59..6073f83e8c8a 100644 --- a/stdlib/importlib/resources/_common.pyi +++ b/stdlib/importlib/resources/_common.pyi @@ -12,7 +12,7 @@ if sys.version_info >= (3, 12): Anchor: TypeAlias = Package def package_to_anchor( - func: Callable[[Anchor | None], Traversable], + func: Callable[[Anchor | None], Traversable] ) -> Callable[[Anchor | None, Anchor | None], Traversable]: ... @overload def files(anchor: Anchor | None = None) -> Traversable: ... From a9dcfc6ef3742fef281e0d0d3323bb7d0a71517a Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Mon, 15 Jul 2024 21:38:43 -0500 Subject: [PATCH 35/66] Tweak --- stdlib/importlib/resources/_functional.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/importlib/resources/_functional.pyi b/stdlib/importlib/resources/_functional.pyi index b0c1a74d5dcd..a60ac106a28f 100644 --- a/stdlib/importlib/resources/_functional.pyi +++ b/stdlib/importlib/resources/_functional.pyi @@ -1,7 +1,7 @@ from _typeshed import StrPath from collections.abc import Iterator from contextlib import AbstractContextManager -from importlib.resources._common import Anchor +from importlib.resources._common import Anchor as Anchor from io import TextIOWrapper from pathlib import Path from typing import BinaryIO, overload From 34d62ebe51ce5c6f6e0153dbd3778ad903402e17 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Mon, 15 Jul 2024 21:41:55 -0500 Subject: [PATCH 36/66] Tweak --- stdlib/importlib/resources/_common.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/importlib/resources/_common.pyi b/stdlib/importlib/resources/_common.pyi index 6073f83e8c8a..7e2f274ff766 100644 --- a/stdlib/importlib/resources/_common.pyi +++ b/stdlib/importlib/resources/_common.pyi @@ -1,7 +1,7 @@ import sys import types from contextlib import AbstractContextManager -from importlib.abc import ResourceReader, Traversable +from importlib.abc import ResourceReader, Traversable as Traversable from pathlib import Path from typing import Callable, overload from typing_extensions import TypeAlias, deprecated @@ -12,7 +12,7 @@ if sys.version_info >= (3, 12): Anchor: TypeAlias = Package def package_to_anchor( - func: Callable[[Anchor | None], Traversable] + func: Callable[[Anchor | None], Traversable], ) -> Callable[[Anchor | None, Anchor | None], Traversable]: ... @overload def files(anchor: Anchor | None = None) -> Traversable: ... From e9e7737eff499175cf9f1d31141a3ab56e78bf1e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 16 Jul 2024 02:43:32 +0000 Subject: [PATCH 37/66] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/importlib/resources/_common.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/importlib/resources/_common.pyi b/stdlib/importlib/resources/_common.pyi index 7e2f274ff766..6c1ae094a683 100644 --- a/stdlib/importlib/resources/_common.pyi +++ b/stdlib/importlib/resources/_common.pyi @@ -12,7 +12,7 @@ if sys.version_info >= (3, 12): Anchor: TypeAlias = Package def package_to_anchor( - func: Callable[[Anchor | None], Traversable], + func: Callable[[Anchor | None], Traversable] ) -> Callable[[Anchor | None, Anchor | None], Traversable]: ... @overload def files(anchor: Anchor | None = None) -> Traversable: ... From 4f999f8dd0184e4e0c47dd177fe48ac73f7d05f9 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Mon, 15 Jul 2024 21:44:03 -0500 Subject: [PATCH 38/66] Fix --- stdlib/importlib/resources/_common.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/importlib/resources/_common.pyi b/stdlib/importlib/resources/_common.pyi index 6c1ae094a683..dc9897c72815 100644 --- a/stdlib/importlib/resources/_common.pyi +++ b/stdlib/importlib/resources/_common.pyi @@ -1,7 +1,8 @@ import sys import types from contextlib import AbstractContextManager -from importlib.abc import ResourceReader, Traversable as Traversable +from importlib.abc import ResourceReader +from importlib.resources.abc import Traversable from pathlib import Path from typing import Callable, overload from typing_extensions import TypeAlias, deprecated From 00ff92b1691c5463f38d8c5665e84dce9c46c43a Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Mon, 15 Jul 2024 21:46:16 -0500 Subject: [PATCH 39/66] Tweaks --- stdlib/importlib/resources/_common.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/importlib/resources/_common.pyi b/stdlib/importlib/resources/_common.pyi index dc9897c72815..58a4ca94d8ef 100644 --- a/stdlib/importlib/resources/_common.pyi +++ b/stdlib/importlib/resources/_common.pyi @@ -2,7 +2,7 @@ import sys import types from contextlib import AbstractContextManager from importlib.abc import ResourceReader -from importlib.resources.abc import Traversable +from importlib.resources.abc import Traversable as Traversable from pathlib import Path from typing import Callable, overload from typing_extensions import TypeAlias, deprecated @@ -13,7 +13,7 @@ if sys.version_info >= (3, 12): Anchor: TypeAlias = Package def package_to_anchor( - func: Callable[[Anchor | None], Traversable] + func: Callable[[Anchor | None], Traversable], ) -> Callable[[Anchor | None, Anchor | None], Traversable]: ... @overload def files(anchor: Anchor | None = None) -> Traversable: ... From 1880aa18f02c0f992a11880aec629c3c2fdc12a9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 16 Jul 2024 02:48:16 +0000 Subject: [PATCH 40/66] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/importlib/resources/_common.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/importlib/resources/_common.pyi b/stdlib/importlib/resources/_common.pyi index 58a4ca94d8ef..cee932f4bbcc 100644 --- a/stdlib/importlib/resources/_common.pyi +++ b/stdlib/importlib/resources/_common.pyi @@ -13,7 +13,7 @@ if sys.version_info >= (3, 12): Anchor: TypeAlias = Package def package_to_anchor( - func: Callable[[Anchor | None], Traversable], + func: Callable[[Anchor | None], Traversable] ) -> Callable[[Anchor | None, Anchor | None], Traversable]: ... @overload def files(anchor: Anchor | None = None) -> Traversable: ... From 8837644978b2db41f65a40604a8e48a4a03888b0 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Mon, 15 Jul 2024 21:51:00 -0500 Subject: [PATCH 41/66] Pos isn't required --- stdlib/importlib/abc.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/importlib/abc.pyi b/stdlib/importlib/abc.pyi index 3937481159dc..4a0a70d0930d 100644 --- a/stdlib/importlib/abc.pyi +++ b/stdlib/importlib/abc.pyi @@ -145,10 +145,10 @@ if sys.version_info >= (3, 9): # which is not the case. @overload @abstractmethod - def open(self, mode: Literal["r"] = "r", /, *, encoding: str | None = None, errors: str | None = None) -> IO[str]: ... + def open(self, mode: Literal["r"] = "r", *, encoding: str | None = None, errors: str | None = None) -> IO[str]: ... @overload @abstractmethod - def open(self, mode: Literal["rb"], /) -> IO[bytes]: ... + def open(self, mode: Literal["rb"]) -> IO[bytes]: ... @property @abstractmethod def name(self) -> str: ... From 56b8e78d319c46fedcf456bf6184818ef5c32ef8 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Mon, 15 Jul 2024 21:53:51 -0500 Subject: [PATCH 42/66] Tweak --- stdlib/importlib/resources/_common.pyi | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/stdlib/importlib/resources/_common.pyi b/stdlib/importlib/resources/_common.pyi index cee932f4bbcc..7e2f274ff766 100644 --- a/stdlib/importlib/resources/_common.pyi +++ b/stdlib/importlib/resources/_common.pyi @@ -1,8 +1,7 @@ import sys import types from contextlib import AbstractContextManager -from importlib.abc import ResourceReader -from importlib.resources.abc import Traversable as Traversable +from importlib.abc import ResourceReader, Traversable as Traversable from pathlib import Path from typing import Callable, overload from typing_extensions import TypeAlias, deprecated @@ -13,7 +12,7 @@ if sys.version_info >= (3, 12): Anchor: TypeAlias = Package def package_to_anchor( - func: Callable[[Anchor | None], Traversable] + func: Callable[[Anchor | None], Traversable], ) -> Callable[[Anchor | None, Anchor | None], Traversable]: ... @overload def files(anchor: Anchor | None = None) -> Traversable: ... From 1b35fd3ab097894a97d2954b0bf734a16a288c73 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 16 Jul 2024 02:55:29 +0000 Subject: [PATCH 43/66] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/importlib/resources/_common.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/importlib/resources/_common.pyi b/stdlib/importlib/resources/_common.pyi index 7e2f274ff766..6c1ae094a683 100644 --- a/stdlib/importlib/resources/_common.pyi +++ b/stdlib/importlib/resources/_common.pyi @@ -12,7 +12,7 @@ if sys.version_info >= (3, 12): Anchor: TypeAlias = Package def package_to_anchor( - func: Callable[[Anchor | None], Traversable], + func: Callable[[Anchor | None], Traversable] ) -> Callable[[Anchor | None, Anchor | None], Traversable]: ... @overload def files(anchor: Anchor | None = None) -> Traversable: ... From b2c58a186fa1c5616d519ed99343d7c2551d4538 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Mon, 12 Aug 2024 10:56:08 -0500 Subject: [PATCH 44/66] Use collections.abc.Callable --- stdlib/importlib/resources/_common.pyi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stdlib/importlib/resources/_common.pyi b/stdlib/importlib/resources/_common.pyi index 6c1ae094a683..26e8e4a13737 100644 --- a/stdlib/importlib/resources/_common.pyi +++ b/stdlib/importlib/resources/_common.pyi @@ -1,9 +1,10 @@ import sys import types +from collections.abc import Callable from contextlib import AbstractContextManager from importlib.abc import ResourceReader, Traversable as Traversable from pathlib import Path -from typing import Callable, overload +from typing import overload from typing_extensions import TypeAlias, deprecated Package: TypeAlias = str | types.ModuleType @@ -12,7 +13,7 @@ if sys.version_info >= (3, 12): Anchor: TypeAlias = Package def package_to_anchor( - func: Callable[[Anchor | None], Traversable] + func: Callable[[Anchor | None], Traversable], ) -> Callable[[Anchor | None, Anchor | None], Traversable]: ... @overload def files(anchor: Anchor | None = None) -> Traversable: ... From 38ca04716d727e330428f3a0539d36adc8cf2514 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 12 Aug 2024 15:57:53 +0000 Subject: [PATCH 45/66] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/importlib/resources/_common.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/importlib/resources/_common.pyi b/stdlib/importlib/resources/_common.pyi index 26e8e4a13737..8c76d11ee2ce 100644 --- a/stdlib/importlib/resources/_common.pyi +++ b/stdlib/importlib/resources/_common.pyi @@ -13,7 +13,7 @@ if sys.version_info >= (3, 12): Anchor: TypeAlias = Package def package_to_anchor( - func: Callable[[Anchor | None], Traversable], + func: Callable[[Anchor | None], Traversable] ) -> Callable[[Anchor | None, Anchor | None], Traversable]: ... @overload def files(anchor: Anchor | None = None) -> Traversable: ... From 455d5ad6a317b42391e894c4666d4fae9ad07c99 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Sun, 15 Sep 2024 12:46:41 -0500 Subject: [PATCH 46/66] Add ignore --- pyrightconfig.stricter.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index 05e6455833a1..08e7f45d29aa 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -6,6 +6,8 @@ "stubs", ], "exclude": [ + // Pyright doesn't recognize imports that don't exist in older versions of Python, even when conditionally nested. + "stdlib/importlib/resources/_functional.pyi", // test cases use a custom pyrightconfig file "**/@tests/test_cases", "stdlib/distutils/command", From a764ad0aeea1bce691710e075ef999e2148d66ed Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Sun, 15 Sep 2024 12:54:24 -0500 Subject: [PATCH 47/66] Add appropiate ignores --- stdlib/@tests/stubtest_allowlists/common.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/stdlib/@tests/stubtest_allowlists/common.txt b/stdlib/@tests/stubtest_allowlists/common.txt index 01b23cd7a274..912bdc582bd1 100644 --- a/stdlib/@tests/stubtest_allowlists/common.txt +++ b/stdlib/@tests/stubtest_allowlists/common.txt @@ -238,6 +238,13 @@ importlib.machinery.WindowsRegistryFinder.DEBUG_BUILD importlib.machinery.WindowsRegistryFinder.REGISTRY_KEY importlib.machinery.WindowsRegistryFinder.REGISTRY_KEY_DEBUG +# Deprecated argument is supported at runtime by renaming it through a decorator. +importlib.resources._common.Traversable.files +# The documentation and runtime protocol allows *args, **kwargs arguments, +# but this would mean that all implementers would have to support them, +# which is not the case. +importlib.resources._common.Traversable.open + # Undocumented implementation details profile.Profile.dispatch profile.Profile.fake_code From 1c74e63a488513ff69fe163522f347eda5e29a54 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Sun, 15 Sep 2024 12:56:12 -0500 Subject: [PATCH 48/66] Fix --- stdlib/@tests/stubtest_allowlists/common.txt | 7 ------- stdlib/@tests/stubtest_allowlists/py313.txt | 3 +++ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/common.txt b/stdlib/@tests/stubtest_allowlists/common.txt index 912bdc582bd1..01b23cd7a274 100644 --- a/stdlib/@tests/stubtest_allowlists/common.txt +++ b/stdlib/@tests/stubtest_allowlists/common.txt @@ -238,13 +238,6 @@ importlib.machinery.WindowsRegistryFinder.DEBUG_BUILD importlib.machinery.WindowsRegistryFinder.REGISTRY_KEY importlib.machinery.WindowsRegistryFinder.REGISTRY_KEY_DEBUG -# Deprecated argument is supported at runtime by renaming it through a decorator. -importlib.resources._common.Traversable.files -# The documentation and runtime protocol allows *args, **kwargs arguments, -# but this would mean that all implementers would have to support them, -# which is not the case. -importlib.resources._common.Traversable.open - # Undocumented implementation details profile.Profile.dispatch profile.Profile.fake_code diff --git a/stdlib/@tests/stubtest_allowlists/py313.txt b/stdlib/@tests/stubtest_allowlists/py313.txt index 7adc273a8817..a59316367d4d 100644 --- a/stdlib/@tests/stubtest_allowlists/py313.txt +++ b/stdlib/@tests/stubtest_allowlists/py313.txt @@ -141,9 +141,12 @@ platform.uname_result.processor unittest.TestCase.__init_subclass__ unittest.case.TestCase.__init_subclass__ +# Deprecated argument is supported at runtime by renaming it through a decorator. +importlib.resources._common.Traversable.files # Problematic protocol signature at runtime, see source code comments. importlib.abc.Traversable.open importlib.resources.abc.Traversable.open +importlib.resources._common.Traversable.open # Deprecation wrapper classes; their methods are just pass-through, so we can ignore them. importlib.metadata.DeprecatedNonAbstract.__new__ From 87c1e55bb0691f557776ee6138f09e97c646c686 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Sun, 15 Sep 2024 12:56:26 -0500 Subject: [PATCH 49/66] Fix --- stdlib/@tests/stubtest_allowlists/py313.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/@tests/stubtest_allowlists/py313.txt b/stdlib/@tests/stubtest_allowlists/py313.txt index a59316367d4d..e9b7b46dce9c 100644 --- a/stdlib/@tests/stubtest_allowlists/py313.txt +++ b/stdlib/@tests/stubtest_allowlists/py313.txt @@ -142,7 +142,7 @@ unittest.TestCase.__init_subclass__ unittest.case.TestCase.__init_subclass__ # Deprecated argument is supported at runtime by renaming it through a decorator. -importlib.resources._common.Traversable.files +importlib.resources._common.files # Problematic protocol signature at runtime, see source code comments. importlib.abc.Traversable.open importlib.resources.abc.Traversable.open From 6786f6c40e06f393e3671454d3063222eb881465 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Sun, 15 Sep 2024 13:00:37 -0500 Subject: [PATCH 50/66] Add ignore --- pyrightconfig.stricter.json | 2 -- stdlib/importlib/resources/_functional.pyi | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index 08e7f45d29aa..05e6455833a1 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -6,8 +6,6 @@ "stubs", ], "exclude": [ - // Pyright doesn't recognize imports that don't exist in older versions of Python, even when conditionally nested. - "stdlib/importlib/resources/_functional.pyi", // test cases use a custom pyrightconfig file "**/@tests/test_cases", "stdlib/distutils/command", diff --git a/stdlib/importlib/resources/_functional.pyi b/stdlib/importlib/resources/_functional.pyi index a60ac106a28f..e387640e356d 100644 --- a/stdlib/importlib/resources/_functional.pyi +++ b/stdlib/importlib/resources/_functional.pyi @@ -1,3 +1,6 @@ +# Pyright doesn't recognize _common is always present in 3.13+ +# pyright: reportMissingTypeStubs=false + from _typeshed import StrPath from collections.abc import Iterator from contextlib import AbstractContextManager From bced879713a8527a886b0cd38bb494519ab75fa7 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Sun, 15 Sep 2024 13:02:58 -0500 Subject: [PATCH 51/66] Account for older versions --- stdlib/@tests/stubtest_allowlists/py311.txt | 3 +++ stdlib/@tests/stubtest_allowlists/py312.txt | 3 +++ 2 files changed, 6 insertions(+) diff --git a/stdlib/@tests/stubtest_allowlists/py311.txt b/stdlib/@tests/stubtest_allowlists/py311.txt index 308855f8f00b..ab75f73f1d2f 100644 --- a/stdlib/@tests/stubtest_allowlists/py311.txt +++ b/stdlib/@tests/stubtest_allowlists/py311.txt @@ -176,9 +176,12 @@ platform.uname_result.processor unittest.TestCase.__init_subclass__ unittest.case.TestCase.__init_subclass__ +# Deprecated argument is supported at runtime by renaming it through a decorator. +importlib.resources._common.files # Problematic protocol signature at runtime, see source code comments. importlib.abc.Traversable.open importlib.resources.abc.Traversable.open +importlib.resources._common.Traversable.open # Deprecation wrapper classes; their methods are just pass-through, so we can ignore them. importlib.metadata.DeprecatedList.reverse diff --git a/stdlib/@tests/stubtest_allowlists/py312.txt b/stdlib/@tests/stubtest_allowlists/py312.txt index 8b02abd9621c..008a4e54aa11 100644 --- a/stdlib/@tests/stubtest_allowlists/py312.txt +++ b/stdlib/@tests/stubtest_allowlists/py312.txt @@ -164,9 +164,12 @@ platform.uname_result.processor unittest.TestCase.__init_subclass__ unittest.case.TestCase.__init_subclass__ +# Deprecated argument is supported at runtime by renaming it through a decorator. +importlib.resources._common.files # Problematic protocol signature at runtime, see source code comments. importlib.abc.Traversable.open importlib.resources.abc.Traversable.open +importlib.resources._common.Traversable.open # Deprecation wrapper classes; their methods are just pass-through, so we can ignore them. importlib.metadata.DeprecatedNonAbstract.__new__ From e59c3492d10fa1fca637f684a90392667dadbd9a Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Sun, 15 Sep 2024 13:04:44 -0500 Subject: [PATCH 52/66] Fix --- stdlib/@tests/stubtest_allowlists/py311.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/py311.txt b/stdlib/@tests/stubtest_allowlists/py311.txt index ab75f73f1d2f..2fe631ed5553 100644 --- a/stdlib/@tests/stubtest_allowlists/py311.txt +++ b/stdlib/@tests/stubtest_allowlists/py311.txt @@ -176,8 +176,6 @@ platform.uname_result.processor unittest.TestCase.__init_subclass__ unittest.case.TestCase.__init_subclass__ -# Deprecated argument is supported at runtime by renaming it through a decorator. -importlib.resources._common.files # Problematic protocol signature at runtime, see source code comments. importlib.abc.Traversable.open importlib.resources.abc.Traversable.open From 6b85a45192318342b422ee58bc251238899bb795 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Sun, 15 Sep 2024 13:08:41 -0500 Subject: [PATCH 53/66] Fixes --- stdlib/@tests/stubtest_allowlists/py312.txt | 1 + stdlib/@tests/stubtest_allowlists/py313.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/stdlib/@tests/stubtest_allowlists/py312.txt b/stdlib/@tests/stubtest_allowlists/py312.txt index 008a4e54aa11..816cf45940a0 100644 --- a/stdlib/@tests/stubtest_allowlists/py312.txt +++ b/stdlib/@tests/stubtest_allowlists/py312.txt @@ -166,6 +166,7 @@ unittest.case.TestCase.__init_subclass__ # Deprecated argument is supported at runtime by renaming it through a decorator. importlib.resources._common.files +importlib.resources.files # Problematic protocol signature at runtime, see source code comments. importlib.abc.Traversable.open importlib.resources.abc.Traversable.open diff --git a/stdlib/@tests/stubtest_allowlists/py313.txt b/stdlib/@tests/stubtest_allowlists/py313.txt index e9b7b46dce9c..4ebc2bd57051 100644 --- a/stdlib/@tests/stubtest_allowlists/py313.txt +++ b/stdlib/@tests/stubtest_allowlists/py313.txt @@ -143,6 +143,7 @@ unittest.case.TestCase.__init_subclass__ # Deprecated argument is supported at runtime by renaming it through a decorator. importlib.resources._common.files +importlib.resources.files # Problematic protocol signature at runtime, see source code comments. importlib.abc.Traversable.open importlib.resources.abc.Traversable.open From 622360c86ce00a56df5ce574b8ade711d583cdd9 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Sun, 15 Sep 2024 13:12:00 -0500 Subject: [PATCH 54/66] Tweak --- stdlib/importlib/resources/_functional.pyi | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/stdlib/importlib/resources/_functional.pyi b/stdlib/importlib/resources/_functional.pyi index e387640e356d..62bc5fbce49c 100644 --- a/stdlib/importlib/resources/_functional.pyi +++ b/stdlib/importlib/resources/_functional.pyi @@ -1,10 +1,9 @@ # Pyright doesn't recognize _common is always present in 3.13+ # pyright: reportMissingTypeStubs=false - from _typeshed import StrPath from collections.abc import Iterator from contextlib import AbstractContextManager -from importlib.resources._common import Anchor as Anchor +from importlib.resources._common import Anchor from io import TextIOWrapper from pathlib import Path from typing import BinaryIO, overload From 9de2ab63aeccc93afb40d688ad10a72d1269c7b7 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Sun, 15 Sep 2024 13:14:05 -0500 Subject: [PATCH 55/66] Add block --- stdlib/importlib/resources/_functional.pyi | 56 +++++++++++----------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/stdlib/importlib/resources/_functional.pyi b/stdlib/importlib/resources/_functional.pyi index 62bc5fbce49c..97e46bdf0a53 100644 --- a/stdlib/importlib/resources/_functional.pyi +++ b/stdlib/importlib/resources/_functional.pyi @@ -1,28 +1,30 @@ -# Pyright doesn't recognize _common is always present in 3.13+ -# pyright: reportMissingTypeStubs=false -from _typeshed import StrPath -from collections.abc import Iterator -from contextlib import AbstractContextManager -from importlib.resources._common import Anchor -from io import TextIOWrapper -from pathlib import Path -from typing import BinaryIO, overload -from typing_extensions import Unpack +import sys -def open_binary(anchor: Anchor, *path_names: StrPath) -> BinaryIO: ... -@overload -def open_text( - anchor: Anchor, *path_names: Unpack[tuple[StrPath]], encoding: str | None = "utf-8", errors: str | None = "strict" -) -> TextIOWrapper: ... -@overload -def open_text(anchor: Anchor, *path_names: StrPath, encoding: str | None, errors: str | None = "strict") -> TextIOWrapper: ... -def read_binary(anchor: Anchor, *path_names: StrPath) -> bytes: ... -@overload -def read_text( - anchor: Anchor, *path_names: Unpack[tuple[StrPath]], encoding: str | None = "utf-8", errors: str | None = "strict" -) -> str: ... -@overload -def read_text(anchor: Anchor, *path_names: StrPath, encoding: str | None, errors: str | None = "strict") -> str: ... -def path(anchor: Anchor, *path_names: StrPath) -> AbstractContextManager[Path]: ... -def is_resource(anchor: Anchor, *path_names: StrPath) -> bool: ... -def contents(anchor: Anchor, *path_names: StrPath) -> Iterator[str]: ... +# Even though this file is 3.13+ only, Pyright will complain in stubtest for older versions. +if sys.version_info >= (3, 13): + from _typeshed import StrPath + from collections.abc import Iterator + from contextlib import AbstractContextManager + from importlib.resources._common import Anchor + from io import TextIOWrapper + from pathlib import Path + from typing import BinaryIO, overload + from typing_extensions import Unpack + + def open_binary(anchor: Anchor, *path_names: StrPath) -> BinaryIO: ... + @overload + def open_text( + anchor: Anchor, *path_names: Unpack[tuple[StrPath]], encoding: str | None = "utf-8", errors: str | None = "strict" + ) -> TextIOWrapper: ... + @overload + def open_text(anchor: Anchor, *path_names: StrPath, encoding: str | None, errors: str | None = "strict") -> TextIOWrapper: ... + def read_binary(anchor: Anchor, *path_names: StrPath) -> bytes: ... + @overload + def read_text( + anchor: Anchor, *path_names: Unpack[tuple[StrPath]], encoding: str | None = "utf-8", errors: str | None = "strict" + ) -> str: ... + @overload + def read_text(anchor: Anchor, *path_names: StrPath, encoding: str | None, errors: str | None = "strict") -> str: ... + def path(anchor: Anchor, *path_names: StrPath) -> AbstractContextManager[Path]: ... + def is_resource(anchor: Anchor, *path_names: StrPath) -> bool: ... + def contents(anchor: Anchor, *path_names: StrPath) -> Iterator[str]: ... From 8190c3c2604e0f443cdc6f4ca08b0250046179f8 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Sun, 15 Sep 2024 13:16:28 -0500 Subject: [PATCH 56/66] Nest _common --- stdlib/importlib/resources/_common.pyi | 44 ++++++++++++++------------ 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/stdlib/importlib/resources/_common.pyi b/stdlib/importlib/resources/_common.pyi index 8c76d11ee2ce..57c29ee59ad8 100644 --- a/stdlib/importlib/resources/_common.pyi +++ b/stdlib/importlib/resources/_common.pyi @@ -9,31 +9,33 @@ from typing_extensions import TypeAlias, deprecated Package: TypeAlias = str | types.ModuleType -if sys.version_info >= (3, 12): - Anchor: TypeAlias = Package +# Even though this file is 3.11+ only, Pyright will complain in stubtest for older versions. +if sys.version_info >= (3, 11): + if sys.version_info >= (3, 12): + Anchor: TypeAlias = Package - def package_to_anchor( - func: Callable[[Anchor | None], Traversable] - ) -> Callable[[Anchor | None, Anchor | None], Traversable]: ... - @overload - def files(anchor: Anchor | None = None) -> Traversable: ... - @overload - @deprecated("First parameter to files is renamed to 'anchor'") - def files(package: Anchor | None = None) -> Traversable: ... + def package_to_anchor( + func: Callable[[Anchor | None], Traversable], + ) -> Callable[[Anchor | None, Anchor | None], Traversable]: ... + @overload + def files(anchor: Anchor | None = None) -> Traversable: ... + @overload + @deprecated("First parameter to files is renamed to 'anchor'") + def files(package: Anchor | None = None) -> Traversable: ... -else: - def files(package: Package) -> Traversable: ... + else: + def files(package: Package) -> Traversable: ... -def get_resource_reader(package: types.ModuleType) -> ResourceReader | None: ... + def get_resource_reader(package: types.ModuleType) -> ResourceReader | None: ... -if sys.version_info >= (3, 12): - def resolve(cand: Anchor | None) -> types.ModuleType: ... + if sys.version_info >= (3, 12): + def resolve(cand: Anchor | None) -> types.ModuleType: ... -else: - def resolve(cand: Package) -> types.ModuleType: ... + else: + def resolve(cand: Package) -> types.ModuleType: ... -if sys.version_info < (3, 12): - def get_package(package: Package) -> types.ModuleType: ... + if sys.version_info < (3, 12): + def get_package(package: Package) -> types.ModuleType: ... -def from_package(package: types.ModuleType) -> Traversable: ... -def as_file(path: Traversable) -> AbstractContextManager[Path]: ... + def from_package(package: types.ModuleType) -> Traversable: ... + def as_file(path: Traversable) -> AbstractContextManager[Path]: ... From 3f3ef73574e325a493014718a5d22f047a3772a8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 15 Sep 2024 18:18:07 +0000 Subject: [PATCH 57/66] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/importlib/resources/_common.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/importlib/resources/_common.pyi b/stdlib/importlib/resources/_common.pyi index 57c29ee59ad8..3f6cc9167f46 100644 --- a/stdlib/importlib/resources/_common.pyi +++ b/stdlib/importlib/resources/_common.pyi @@ -15,7 +15,7 @@ if sys.version_info >= (3, 11): Anchor: TypeAlias = Package def package_to_anchor( - func: Callable[[Anchor | None], Traversable], + func: Callable[[Anchor | None], Traversable] ) -> Callable[[Anchor | None, Anchor | None], Traversable]: ... @overload def files(anchor: Anchor | None = None) -> Traversable: ... From 61d4465b18511aa8c69002025ae04220db4b6327 Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Sun, 15 Sep 2024 13:18:21 -0500 Subject: [PATCH 58/66] Fix --- stdlib/importlib/resources/_common.pyi | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/stdlib/importlib/resources/_common.pyi b/stdlib/importlib/resources/_common.pyi index 3f6cc9167f46..f04f70f25e23 100644 --- a/stdlib/importlib/resources/_common.pyi +++ b/stdlib/importlib/resources/_common.pyi @@ -1,16 +1,17 @@ import sys -import types -from collections.abc import Callable -from contextlib import AbstractContextManager -from importlib.abc import ResourceReader, Traversable as Traversable -from pathlib import Path -from typing import overload -from typing_extensions import TypeAlias, deprecated - -Package: TypeAlias = str | types.ModuleType # Even though this file is 3.11+ only, Pyright will complain in stubtest for older versions. if sys.version_info >= (3, 11): + import types + from collections.abc import Callable + from contextlib import AbstractContextManager + from importlib.abc import ResourceReader, Traversable + from pathlib import Path + from typing import overload + from typing_extensions import TypeAlias, deprecated + + Package: TypeAlias = str | types.ModuleType + if sys.version_info >= (3, 12): Anchor: TypeAlias = Package From 9cfef10c9841fea6d896b76aa13cd16feb712afb Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Sun, 15 Sep 2024 13:20:26 -0500 Subject: [PATCH 59/66] Fixes --- stdlib/@tests/stubtest_allowlists/py311.txt | 1 - stdlib/@tests/stubtest_allowlists/py312.txt | 1 - 2 files changed, 2 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/py311.txt b/stdlib/@tests/stubtest_allowlists/py311.txt index 2fe631ed5553..308855f8f00b 100644 --- a/stdlib/@tests/stubtest_allowlists/py311.txt +++ b/stdlib/@tests/stubtest_allowlists/py311.txt @@ -179,7 +179,6 @@ unittest.case.TestCase.__init_subclass__ # Problematic protocol signature at runtime, see source code comments. importlib.abc.Traversable.open importlib.resources.abc.Traversable.open -importlib.resources._common.Traversable.open # Deprecation wrapper classes; their methods are just pass-through, so we can ignore them. importlib.metadata.DeprecatedList.reverse diff --git a/stdlib/@tests/stubtest_allowlists/py312.txt b/stdlib/@tests/stubtest_allowlists/py312.txt index 816cf45940a0..14500a678fdf 100644 --- a/stdlib/@tests/stubtest_allowlists/py312.txt +++ b/stdlib/@tests/stubtest_allowlists/py312.txt @@ -170,7 +170,6 @@ importlib.resources.files # Problematic protocol signature at runtime, see source code comments. importlib.abc.Traversable.open importlib.resources.abc.Traversable.open -importlib.resources._common.Traversable.open # Deprecation wrapper classes; their methods are just pass-through, so we can ignore them. importlib.metadata.DeprecatedNonAbstract.__new__ From 46921b1a082ec5a437d07ae8f820770f32ceef5c Mon Sep 17 00:00:00 2001 From: Maxwell Muoto <41130755+max-muoto@users.noreply.github.com> Date: Sun, 15 Sep 2024 13:21:53 -0500 Subject: [PATCH 60/66] Fix --- stdlib/@tests/stubtest_allowlists/py313.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/stdlib/@tests/stubtest_allowlists/py313.txt b/stdlib/@tests/stubtest_allowlists/py313.txt index 4ebc2bd57051..8ddbb8fe3089 100644 --- a/stdlib/@tests/stubtest_allowlists/py313.txt +++ b/stdlib/@tests/stubtest_allowlists/py313.txt @@ -147,7 +147,6 @@ importlib.resources.files # Problematic protocol signature at runtime, see source code comments. importlib.abc.Traversable.open importlib.resources.abc.Traversable.open -importlib.resources._common.Traversable.open # Deprecation wrapper classes; their methods are just pass-through, so we can ignore them. importlib.metadata.DeprecatedNonAbstract.__new__ From db7f52ce2ce86bb2d4d13fa69954ff2cd5f1ba6d Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Mon, 16 Sep 2024 12:29:38 -0500 Subject: [PATCH 61/66] Update stdlib/importlib/resources/__init__.pyi Co-authored-by: Sebastian Rittau --- stdlib/importlib/resources/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/importlib/resources/__init__.pyi b/stdlib/importlib/resources/__init__.pyi index 555610eaa6dd..b076f8ab95f9 100644 --- a/stdlib/importlib/resources/__init__.pyi +++ b/stdlib/importlib/resources/__init__.pyi @@ -8,7 +8,7 @@ from typing import Any, BinaryIO, TextIO from typing_extensions import TypeAlias if sys.version_info >= (3, 11): - from importlib.resources._common import Package + from importlib.resources._common import Package as Package else: Package: TypeAlias = str | ModuleType From 60e7c317e66405e2b90e9ea6e9f47bb7d8141815 Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Mon, 16 Sep 2024 12:29:45 -0500 Subject: [PATCH 62/66] Update stdlib/importlib/resources/__init__.pyi Co-authored-by: Sebastian Rittau --- stdlib/importlib/resources/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/importlib/resources/__init__.pyi b/stdlib/importlib/resources/__init__.pyi index b076f8ab95f9..3ef6b07017a8 100644 --- a/stdlib/importlib/resources/__init__.pyi +++ b/stdlib/importlib/resources/__init__.pyi @@ -53,7 +53,7 @@ elif sys.version_info >= (3, 9): def as_file(path: Traversable) -> AbstractContextManager[Path]: ... if sys.version_info >= (3, 11): - from importlib.resources._common import files + from importlib.resources._common import files as files elif sys.version_info >= (3, 9): def files(package: Package) -> Traversable: ... From 51f9a423b4e8ad8cb2e3b560c1f28693b0469404 Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Mon, 16 Sep 2024 12:29:57 -0500 Subject: [PATCH 63/66] Update stdlib/importlib/resources/__init__.pyi Co-authored-by: Sebastian Rittau --- stdlib/importlib/resources/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/importlib/resources/__init__.pyi b/stdlib/importlib/resources/__init__.pyi index 3ef6b07017a8..2c411ac7a84c 100644 --- a/stdlib/importlib/resources/__init__.pyi +++ b/stdlib/importlib/resources/__init__.pyi @@ -48,7 +48,7 @@ else: def contents(package: Package) -> Iterator[str]: ... if sys.version_info >= (3, 11): - from importlib.resources._common import as_file + from importlib.resources._common import as_file as as_file elif sys.version_info >= (3, 9): def as_file(path: Traversable) -> AbstractContextManager[Path]: ... From 8d16119b60f4faa359c70d709dee373bb76bf035 Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Mon, 16 Sep 2024 12:30:04 -0500 Subject: [PATCH 64/66] Update stdlib/importlib/resources/__init__.pyi Co-authored-by: Sebastian Rittau --- stdlib/importlib/resources/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/importlib/resources/__init__.pyi b/stdlib/importlib/resources/__init__.pyi index 2c411ac7a84c..1696faa45dc9 100644 --- a/stdlib/importlib/resources/__init__.pyi +++ b/stdlib/importlib/resources/__init__.pyi @@ -36,7 +36,7 @@ if sys.version_info >= (3, 13): __all__ += ["Anchor"] - from importlib.resources._functional import contents, is_resource, open_binary, open_text, path, read_binary, read_text + from importlib.resources._functional import contents as contents, is_resource as is_resource, open_binary as open_binary, open_text as open_text, path as path, read_binary as read_binary, read_text as read_text else: def open_binary(package: Package, resource: Resource) -> BinaryIO: ... From 751673e4a2364828fb0664d71508c90c29019830 Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Mon, 16 Sep 2024 12:30:10 -0500 Subject: [PATCH 65/66] Update stdlib/@tests/test_cases/check_importlib_resources.py Co-authored-by: Sebastian Rittau --- stdlib/@tests/test_cases/check_importlib_resources.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/stdlib/@tests/test_cases/check_importlib_resources.py b/stdlib/@tests/test_cases/check_importlib_resources.py index c0f6fb0700a1..cf1507389bef 100644 --- a/stdlib/@tests/test_cases/check_importlib_resources.py +++ b/stdlib/@tests/test_cases/check_importlib_resources.py @@ -6,11 +6,8 @@ class _CustomPathLike: - def __init__(self, path: str) -> None: - self.path = path - def __fspath__(self) -> str: - return self.path + return "" if sys.version_info >= (3, 13): From 2587ba7c3954bc3a77ac17e1b8c309ff3d39f59d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 16 Sep 2024 17:32:55 +0000 Subject: [PATCH 66/66] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/importlib/resources/__init__.pyi | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/stdlib/importlib/resources/__init__.pyi b/stdlib/importlib/resources/__init__.pyi index 1696faa45dc9..f82df8c591fa 100644 --- a/stdlib/importlib/resources/__init__.pyi +++ b/stdlib/importlib/resources/__init__.pyi @@ -36,7 +36,15 @@ if sys.version_info >= (3, 13): __all__ += ["Anchor"] - from importlib.resources._functional import contents as contents, is_resource as is_resource, open_binary as open_binary, open_text as open_text, path as path, read_binary as read_binary, read_text as read_text + from importlib.resources._functional import ( + contents as contents, + is_resource as is_resource, + open_binary as open_binary, + open_text as open_text, + path as path, + read_binary as read_binary, + read_text as read_text, + ) else: def open_binary(package: Package, resource: Resource) -> BinaryIO: ...