Make importlib context manager not swallow exceptions (#13733)

This commit is contained in:
Neil Mitchell authored and GitHub committed 2025-03-28 15:16:17 +01:00
1 parent 2a7a601a5c
commit 7335dfa7f9
3 files changed
+7 -7

No files matched your search

+3 -3
View File
@@ -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
+2 -2
View File
@@ -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]]: ...
+2 -2
View File
@@ -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]: ...