mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-06 12:14:27 +08:00
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:
@@ -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: ...
|
||||
|
||||
@@ -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: ...
|
||||
|
||||
Reference in New Issue
Block a user