Add importlib.resources.files for Python 3.9 (#4807)

Co-authored-by: hauntsaninja <>
Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
This commit is contained in:
Hynek Schlawack
2020-12-09 13:47:45 +01:00
committed by GitHub
parent 61c5667b3f
commit cb43535541
3 changed files with 30 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ import sys
import types
from abc import ABCMeta, abstractmethod
from typing import IO, Any, Iterator, Mapping, Optional, Sequence, Tuple, Union
from typing_extensions import Literal
# Loader is exported from this module, but for circular import reasons
# exists in its own stub file (with ModuleSpec and ModuleType).
@@ -70,3 +71,27 @@ if sys.version_info >= (3, 7):
def is_resource(self, name: str) -> bool: ...
@abstractmethod
def contents(self) -> Iterator[str]: ...
if sys.version_info >= (3, 9):
from typing import Protocol, runtime_checkable
@runtime_checkable
class Traversable(Protocol):
@abstractmethod
def iterdir(self) -> Iterator[Traversable]: ...
@abstractmethod
def read_bytes(self) -> bytes: ...
@abstractmethod
def read_text(self, encoding: Optional[str] = ...) -> str: ...
@abstractmethod
def is_dir(self) -> bool: ...
@abstractmethod
def is_file(self) -> bool: ...
@abstractmethod
def joinpath(self, child: Traversable) -> Traversable: ...
@abstractmethod
def __truediv__(self, child: Traversable) -> Traversable: ...
@abstractmethod
def open(self, mode: Literal["r", "rb"] = ..., *args: Any, **kwargs: Any) -> IO: ...
@property
@abstractmethod
def name(self) -> str: ...

View File

@@ -16,3 +16,7 @@ if sys.version_info >= (3, 7):
def path(package: Package, resource: Resource) -> ContextManager[Path]: ...
def is_resource(package: Package, name: str) -> bool: ...
def contents(package: Package) -> Iterator[str]: ...
if sys.version_info >= (3, 9):
from importlib.abc import Traversable
def files(package: Package) -> Traversable: ...