Skip to content

Commit dfaf10d

Browse files
authored
importlib.resources.contents is deprecated (#14835)
1 parent 79bb399 commit dfaf10d

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

stdlib/@tests/test_cases/check_importlib_resources.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ def f(pth: pathlib.Path | str | _CustomPathLike) -> None:
2929
importlib.resources.read_binary("pkg", pth)
3030
importlib.resources.path("pkg", pth)
3131
importlib.resources.is_resource("pkg", pth)
32-
importlib.resources.contents("pkg", pth)
32+
importlib.resources.contents("pkg", pth) # pyright: ignore[reportDeprecated]

stdlib/importlib/resources/__init__.pyi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ from contextlib import AbstractContextManager
55
from pathlib import Path
66
from types import ModuleType
77
from typing import Any, BinaryIO, Literal, TextIO
8-
from typing_extensions import TypeAlias
8+
from typing_extensions import TypeAlias, deprecated
99

1010
if sys.version_info >= (3, 11):
1111
from importlib.resources.abc import Traversable
@@ -64,7 +64,11 @@ else:
6464
def read_text(package: Package, resource: Resource, encoding: str = "utf-8", errors: str = "strict") -> str: ...
6565
def path(package: Package, resource: Resource) -> AbstractContextManager[Path, Literal[False]]: ...
6666
def is_resource(package: Package, name: str) -> bool: ...
67-
def contents(package: Package) -> Iterator[str]: ...
67+
if sys.version_info >= (3, 11):
68+
@deprecated("Deprecated since Python 3.11. Use `files(anchor).iterdir()`.")
69+
def contents(package: Package) -> Iterator[str]: ...
70+
else:
71+
def contents(package: Package) -> Iterator[str]: ...
6872

6973
if sys.version_info >= (3, 11):
7074
from importlib.resources._common import as_file as as_file

stdlib/importlib/resources/_functional.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if sys.version_info >= (3, 13):
99
from io import TextIOWrapper
1010
from pathlib import Path
1111
from typing import BinaryIO, Literal, overload
12-
from typing_extensions import Unpack
12+
from typing_extensions import Unpack, deprecated
1313

1414
def open_binary(anchor: Anchor, *path_names: StrPath) -> BinaryIO: ...
1515
@overload
@@ -27,4 +27,5 @@ if sys.version_info >= (3, 13):
2727
def read_text(anchor: Anchor, *path_names: StrPath, encoding: str | None, errors: str | None = "strict") -> str: ...
2828
def path(anchor: Anchor, *path_names: StrPath) -> AbstractContextManager[Path, Literal[False]]: ...
2929
def is_resource(anchor: Anchor, *path_names: StrPath) -> bool: ...
30+
@deprecated("Deprecated since Python 3.11. Use `files(anchor).iterdir()`.")
3031
def contents(anchor: Anchor, *path_names: StrPath) -> Iterator[str]: ...

0 commit comments

Comments
 (0)