From 7335dfa7f912896045076a4d4cffbceb3c75b8fb Mon Sep 17 00:00:00 2001 From: Neil Mitchell Date: Fri, 28 Mar 2025 14:16:17 +0000 Subject: [PATCH] Make importlib context manager not swallow exceptions (#13733) --- stdlib/importlib/resources/__init__.pyi | 6 +++--- stdlib/importlib/resources/_common.pyi | 4 ++-- stdlib/importlib/resources/_functional.pyi | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/stdlib/importlib/resources/__init__.pyi b/stdlib/importlib/resources/__init__.pyi index f82df8c59..a30e6cdce 100644 --- a/stdlib/importlib/resources/__init__.pyi +++ b/stdlib/importlib/resources/__init__.pyi @@ -4,7 +4,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, Literal, TextIO from typing_extensions import TypeAlias if sys.version_info >= (3, 11): @@ -51,14 +51,14 @@ else: 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 path(package: Package, resource: Resource) -> AbstractContextManager[Path, Literal[False]]: ... def is_resource(package: Package, name: str) -> bool: ... def contents(package: Package) -> Iterator[str]: ... if sys.version_info >= (3, 11): from importlib.resources._common import as_file as as_file elif sys.version_info >= (3, 9): - def as_file(path: Traversable) -> AbstractContextManager[Path]: ... + def as_file(path: Traversable) -> AbstractContextManager[Path, Literal[False]]: ... if sys.version_info >= (3, 11): from importlib.resources._common import files as files diff --git a/stdlib/importlib/resources/_common.pyi b/stdlib/importlib/resources/_common.pyi index f1056f62e..d6a943654 100644 --- a/stdlib/importlib/resources/_common.pyi +++ b/stdlib/importlib/resources/_common.pyi @@ -7,7 +7,7 @@ if sys.version_info >= (3, 11): from contextlib import AbstractContextManager from importlib.abc import ResourceReader, Traversable from pathlib import Path - from typing import overload + from typing import Literal, overload from typing_extensions import TypeAlias, deprecated Package: TypeAlias = str | types.ModuleType @@ -39,4 +39,4 @@ if sys.version_info >= (3, 11): def get_package(package: Package) -> types.ModuleType: ... def from_package(package: types.ModuleType) -> Traversable: ... - def as_file(path: Traversable) -> AbstractContextManager[Path]: ... + def as_file(path: Traversable) -> AbstractContextManager[Path, Literal[False]]: ... diff --git a/stdlib/importlib/resources/_functional.pyi b/stdlib/importlib/resources/_functional.pyi index 97e46bdf0..50f3405f9 100644 --- a/stdlib/importlib/resources/_functional.pyi +++ b/stdlib/importlib/resources/_functional.pyi @@ -8,7 +8,7 @@ if sys.version_info >= (3, 13): from importlib.resources._common import Anchor from io import TextIOWrapper from pathlib import Path - from typing import BinaryIO, overload + from typing import BinaryIO, Literal, overload from typing_extensions import Unpack def open_binary(anchor: Anchor, *path_names: StrPath) -> BinaryIO: ... @@ -25,6 +25,6 @@ if sys.version_info >= (3, 13): ) -> 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 path(anchor: Anchor, *path_names: StrPath) -> AbstractContextManager[Path, Literal[False]]: ... def is_resource(anchor: Anchor, *path_names: StrPath) -> bool: ... def contents(anchor: Anchor, *path_names: StrPath) -> Iterator[str]: ...