mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-01-11 14:08:22 +08:00
Update importlib.resources types (#8658)
* Replace `Str[OrBytes]Path` with `str` A filesystem path is not valid as an abstract resource. `TraversableResources` cannot only accept strings if `ResourceReader` accepts both bytes and strings. `importlib.resources` does not work with bytes in any case and `ResourceReader` is typed as taking a `typing.Text` object in `importlib.resources`' source code. * Update `joinpath` signature from Python 3.11
This commit is contained in:
@@ -1,14 +1,6 @@
|
||||
import sys
|
||||
import types
|
||||
from _typeshed import (
|
||||
OpenBinaryMode,
|
||||
OpenBinaryModeReading,
|
||||
OpenBinaryModeUpdating,
|
||||
OpenBinaryModeWriting,
|
||||
OpenTextMode,
|
||||
StrOrBytesPath,
|
||||
StrPath,
|
||||
)
|
||||
from _typeshed import OpenBinaryMode, OpenBinaryModeReading, OpenBinaryModeUpdating, OpenBinaryModeWriting, OpenTextMode
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from collections.abc import Iterator, Mapping, Sequence
|
||||
from importlib.machinery import ModuleSpec
|
||||
@@ -93,9 +85,9 @@ class FileLoader(ResourceLoader, ExecutionLoader, metaclass=ABCMeta):
|
||||
|
||||
class ResourceReader(metaclass=ABCMeta):
|
||||
@abstractmethod
|
||||
def open_resource(self, resource: StrOrBytesPath) -> IO[bytes]: ...
|
||||
def open_resource(self, resource: str) -> IO[bytes]: ...
|
||||
@abstractmethod
|
||||
def resource_path(self, resource: StrOrBytesPath) -> str: ...
|
||||
def resource_path(self, resource: str) -> str: ...
|
||||
if sys.version_info >= (3, 10):
|
||||
@abstractmethod
|
||||
def is_resource(self, path: str) -> bool: ...
|
||||
@@ -115,8 +107,12 @@ if sys.version_info >= (3, 9):
|
||||
def is_file(self) -> bool: ...
|
||||
@abstractmethod
|
||||
def iterdir(self) -> Iterator[Traversable]: ...
|
||||
@abstractmethod
|
||||
def joinpath(self, child: StrPath) -> Traversable: ...
|
||||
if sys.version_info >= (3, 11):
|
||||
@abstractmethod
|
||||
def joinpath(self, *descendants: str) -> Traversable: ...
|
||||
else:
|
||||
@abstractmethod
|
||||
def joinpath(self, child: str) -> Traversable: ...
|
||||
# The .open method comes from pathlib.pyi and should be kept in sync.
|
||||
@overload
|
||||
@abstractmethod
|
||||
@@ -180,7 +176,7 @@ if sys.version_info >= (3, 9):
|
||||
@property
|
||||
def name(self) -> str: ...
|
||||
@abstractmethod
|
||||
def __truediv__(self, child: StrPath) -> Traversable: ...
|
||||
def __truediv__(self, child: str) -> Traversable: ...
|
||||
@abstractmethod
|
||||
def read_bytes(self) -> bytes: ...
|
||||
@abstractmethod
|
||||
@@ -189,7 +185,7 @@ if sys.version_info >= (3, 9):
|
||||
class TraversableResources(ResourceReader):
|
||||
@abstractmethod
|
||||
def files(self) -> Traversable: ...
|
||||
def open_resource(self, resource: StrPath) -> BufferedReader: ... # type: ignore[override]
|
||||
def open_resource(self, resource: str) -> BufferedReader: ... # type: ignore[override]
|
||||
def resource_path(self, resource: Any) -> NoReturn: ...
|
||||
def is_resource(self, path: StrPath) -> bool: ...
|
||||
def is_resource(self, path: str) -> bool: ...
|
||||
def contents(self) -> Iterator[str]: ...
|
||||
|
||||
Reference in New Issue
Block a user