8000 Make importlib context manager not swallow exceptions by ndmitchell · Pull Request #13733 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions stdlib/importlib/resources/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions stdlib/importlib/resources/_common.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]]: ...
4 changes: 2 additions & 2 deletions stdlib/importlib/resources/_functional.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand All @@ -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]: ...
0