Skip to content

Commit cb43535

Browse files
hyneksrittau
andauthored
Add importlib.resources.files for Python 3.9 (#4807)
Co-authored-by: hauntsaninja <> Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
1 parent 61c5667 commit cb43535

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

stdlib/3/importlib/abc.pyi

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import sys
33
import types
44
from abc import ABCMeta, abstractmethod
55
from typing import IO, Any, Iterator, Mapping, Optional, Sequence, Tuple, Union
6+
from typing_extensions import Literal
67

78
# Loader is exported from this module, but for circular import reasons
89
# exists in its own stub file (with ModuleSpec and ModuleType).
@@ -70,3 +71,27 @@ if sys.version_info >= (3, 7):
7071
def is_resource(self, name: str) -> bool: ...
7172
@abstractmethod
7273
def contents(self) -> Iterator[str]: ...
74+
75+
if sys.version_info >= (3, 9):
76+
from typing import Protocol, runtime_checkable
77+
@runtime_checkable
78+
class Traversable(Protocol):
79+
@abstractmethod
80+
def iterdir(self) -> Iterator[Traversable]: ...
81+
@abstractmethod
82+
def read_bytes(self) -> bytes: ...
83+
@abstractmethod
84+
def read_text(self, encoding: Optional[str] = ...) -> str: ...
85+
@abstractmethod
86+
def is_dir(self) -> bool: ...
87+
@abstractmethod
88+
def is_file(self) -> bool: ...
89+
@abstractmethod
90+
def joinpath(self, child: Traversable) -> Traversable: ...
91+
@abstractmethod
92+
def __truediv__(self, child: Traversable) -> Traversable: ...
93+
@abstractmethod
94+
def open(self, mode: Literal["r", "rb"] = ..., *args: Any, **kwargs: Any) -> IO: ...
95+
@property
96+
@abstractmethod
97+
def name(self) -> str: ...

stdlib/3/importlib/resources.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ if sys.version_info >= (3, 7):
1616
def path(package: Package, resource: Resource) -> ContextManager[Path]: ...
1717
def is_resource(package: Package, name: str) -> bool: ...
1818
def contents(package: Package) -> Iterator[str]: ...
19+
20+
if sys.version_info >= (3, 9):
21+
from importlib.abc import Traversable
22+
def files(package: Package) -> Traversable: ...

tests/stubtest_whitelists/py39.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ hmac.new # Stub is a white lie; see comments in the stub
5151
http.client.HTTPSConnection.__init__
5252
http.cookiejar.DefaultCookiePolicy.__init__
5353
http.server.SimpleHTTPRequestHandler.__init__
54+
importlib.abc.Traversable.__init__ # Inherits __init__ from typing.Protocol
5455
importlib.metadata.DistributionFinder.Context.pattern
5556
importlib.metadata.EntryPointBase
5657
ipaddress.IPv4Interface.hostmask

0 commit comments

Comments
 (0)