mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-27 22:31:12 +08:00
Re-organize directory structure (#4971)
See discussion in #2491 Co-authored-by: Ivan Levkivskyi <ilevkivskyi@dropbox.com>
This commit is contained in:
15
stdlib/importlib/__init__.pyi
Normal file
15
stdlib/importlib/__init__.pyi
Normal file
@@ -0,0 +1,15 @@
|
||||
import types
|
||||
from importlib.abc import Loader
|
||||
from typing import Any, Mapping, Optional, Sequence
|
||||
|
||||
def __import__(
|
||||
name: str,
|
||||
globals: Optional[Mapping[str, Any]] = ...,
|
||||
locals: Optional[Mapping[str, Any]] = ...,
|
||||
fromlist: Sequence[str] = ...,
|
||||
level: int = ...,
|
||||
) -> types.ModuleType: ...
|
||||
def import_module(name: str, package: Optional[str] = ...) -> types.ModuleType: ...
|
||||
def find_loader(name: str, path: Optional[str] = ...) -> Optional[Loader]: ...
|
||||
def invalidate_caches() -> None: ...
|
||||
def reload(module: types.ModuleType) -> types.ModuleType: ...
|
||||
97
stdlib/importlib/abc.pyi
Normal file
97
stdlib/importlib/abc.pyi
Normal file
@@ -0,0 +1,97 @@
|
||||
import os
|
||||
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).
|
||||
from _importlib_modulespec import Loader as Loader, ModuleSpec # Exported
|
||||
|
||||
_Path = Union[bytes, str]
|
||||
|
||||
class Finder(metaclass=ABCMeta): ...
|
||||
|
||||
class ResourceLoader(Loader):
|
||||
@abstractmethod
|
||||
def get_data(self, path: _Path) -> bytes: ...
|
||||
|
||||
class InspectLoader(Loader):
|
||||
def is_package(self, fullname: str) -> bool: ...
|
||||
def get_code(self, fullname: str) -> Optional[types.CodeType]: ...
|
||||
def load_module(self, fullname: str) -> types.ModuleType: ...
|
||||
@abstractmethod
|
||||
def get_source(self, fullname: str) -> Optional[str]: ...
|
||||
def exec_module(self, module: types.ModuleType) -> None: ...
|
||||
@staticmethod
|
||||
def source_to_code(data: Union[bytes, str], path: str = ...) -> types.CodeType: ...
|
||||
|
||||
class ExecutionLoader(InspectLoader):
|
||||
@abstractmethod
|
||||
def get_filename(self, fullname: str) -> _Path: ...
|
||||
def get_code(self, fullname: str) -> Optional[types.CodeType]: ...
|
||||
|
||||
class SourceLoader(ResourceLoader, ExecutionLoader, metaclass=ABCMeta):
|
||||
def path_mtime(self, path: _Path) -> float: ...
|
||||
def set_data(self, path: _Path, data: bytes) -> None: ...
|
||||
def get_source(self, fullname: str) -> Optional[str]: ...
|
||||
def path_stats(self, path: _Path) -> Mapping[str, Any]: ...
|
||||
|
||||
class MetaPathFinder(Finder):
|
||||
def find_module(self, fullname: str, path: Optional[Sequence[_Path]]) -> Optional[Loader]: ...
|
||||
def invalidate_caches(self) -> None: ...
|
||||
# Not defined on the actual class, but expected to exist.
|
||||
def find_spec(
|
||||
self, fullname: str, path: Optional[Sequence[_Path]], target: Optional[types.ModuleType] = ...
|
||||
) -> Optional[ModuleSpec]: ...
|
||||
|
||||
class PathEntryFinder(Finder):
|
||||
def find_module(self, fullname: str) -> Optional[Loader]: ...
|
||||
def find_loader(self, fullname: str) -> Tuple[Optional[Loader], Sequence[_Path]]: ...
|
||||
def invalidate_caches(self) -> None: ...
|
||||
# Not defined on the actual class, but expected to exist.
|
||||
def find_spec(self, fullname: str, target: Optional[types.ModuleType] = ...) -> Optional[ModuleSpec]: ...
|
||||
|
||||
class FileLoader(ResourceLoader, ExecutionLoader, metaclass=ABCMeta):
|
||||
name: str
|
||||
path: _Path
|
||||
def __init__(self, fullname: str, path: _Path) -> None: ...
|
||||
def get_data(self, path: _Path) -> bytes: ...
|
||||
def get_filename(self, fullname: str) -> _Path: ...
|
||||
|
||||
if sys.version_info >= (3, 7):
|
||||
_PathLike = Union[bytes, str, os.PathLike[Any]]
|
||||
class ResourceReader(metaclass=ABCMeta):
|
||||
@abstractmethod
|
||||
def open_resource(self, resource: _PathLike) -> IO[bytes]: ...
|
||||
@abstractmethod
|
||||
def resource_path(self, resource: _PathLike) -> str: ...
|
||||
@abstractmethod
|
||||
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[Any]: ...
|
||||
@property
|
||||
@abstractmethod
|
||||
def name(self) -> str: ...
|
||||
98
stdlib/importlib/machinery.pyi
Normal file
98
stdlib/importlib/machinery.pyi
Normal file
@@ -0,0 +1,98 @@
|
||||
import importlib.abc
|
||||
import types
|
||||
from typing import Callable, List, Optional, Sequence, Tuple, Union
|
||||
|
||||
# ModuleSpec is exported from this module, but for circular import
|
||||
# reasons exists in its own stub file (with Loader and ModuleType).
|
||||
from _importlib_modulespec import Loader, ModuleSpec as ModuleSpec # Exported
|
||||
|
||||
class BuiltinImporter(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader):
|
||||
# MetaPathFinder
|
||||
@classmethod
|
||||
def find_module(cls, fullname: str, path: Optional[Sequence[importlib.abc._Path]]) -> Optional[importlib.abc.Loader]: ...
|
||||
@classmethod
|
||||
def find_spec(
|
||||
cls, fullname: str, path: Optional[Sequence[importlib.abc._Path]], target: Optional[types.ModuleType] = ...
|
||||
) -> Optional[ModuleSpec]: ...
|
||||
# InspectLoader
|
||||
@classmethod
|
||||
def is_package(cls, fullname: str) -> bool: ...
|
||||
@classmethod
|
||||
def load_module(cls, fullname: str) -> types.ModuleType: ...
|
||||
@classmethod
|
||||
def get_code(cls, fullname: str) -> None: ...
|
||||
@classmethod
|
||||
def get_source(cls, fullname: str) -> None: ...
|
||||
# Loader
|
||||
@staticmethod
|
||||
def module_repr(module: types.ModuleType) -> str: ...
|
||||
@classmethod
|
||||
def create_module(cls, spec: ModuleSpec) -> Optional[types.ModuleType]: ...
|
||||
@classmethod
|
||||
def exec_module(cls, module: types.ModuleType) -> None: ...
|
||||
|
||||
class FrozenImporter(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader):
|
||||
# MetaPathFinder
|
||||
@classmethod
|
||||
def find_module(cls, fullname: str, path: Optional[Sequence[importlib.abc._Path]]) -> Optional[importlib.abc.Loader]: ...
|
||||
@classmethod
|
||||
def find_spec(
|
||||
cls, fullname: str, path: Optional[Sequence[importlib.abc._Path]], target: Optional[types.ModuleType] = ...
|
||||
) -> Optional[ModuleSpec]: ...
|
||||
# InspectLoader
|
||||
@classmethod
|
||||
def is_package(cls, fullname: str) -> bool: ...
|
||||
@classmethod
|
||||
def load_module(cls, fullname: str) -> types.ModuleType: ...
|
||||
@classmethod
|
||||
def get_code(cls, fullname: str) -> None: ...
|
||||
@classmethod
|
||||
def get_source(cls, fullname: str) -> None: ...
|
||||
# Loader
|
||||
@staticmethod
|
||||
def module_repr(module: types.ModuleType) -> str: ...
|
||||
@classmethod
|
||||
def create_module(cls, spec: ModuleSpec) -> Optional[types.ModuleType]: ...
|
||||
@staticmethod
|
||||
def exec_module(module: types.ModuleType) -> None: ...
|
||||
|
||||
class WindowsRegistryFinder(importlib.abc.MetaPathFinder):
|
||||
@classmethod
|
||||
def find_module(cls, fullname: str, path: Optional[Sequence[importlib.abc._Path]]) -> Optional[importlib.abc.Loader]: ...
|
||||
@classmethod
|
||||
def find_spec(
|
||||
cls, fullname: str, path: Optional[Sequence[importlib.abc._Path]], target: Optional[types.ModuleType] = ...
|
||||
) -> Optional[ModuleSpec]: ...
|
||||
|
||||
class PathFinder:
|
||||
@classmethod
|
||||
def invalidate_caches(cls) -> None: ...
|
||||
@classmethod
|
||||
def find_spec(
|
||||
cls, fullname: str, path: Optional[Sequence[Union[bytes, str]]] = ..., target: Optional[types.ModuleType] = ...
|
||||
) -> Optional[ModuleSpec]: ...
|
||||
@classmethod
|
||||
def find_module(cls, fullname: str, path: Optional[Sequence[Union[bytes, str]]] = ...) -> Optional[Loader]: ...
|
||||
|
||||
SOURCE_SUFFIXES: List[str]
|
||||
DEBUG_BYTECODE_SUFFIXES: List[str]
|
||||
OPTIMIZED_BYTECODE_SUFFIXES: List[str]
|
||||
BYTECODE_SUFFIXES: List[str]
|
||||
EXTENSION_SUFFIXES: List[str]
|
||||
|
||||
def all_suffixes() -> List[str]: ...
|
||||
|
||||
class FileFinder(importlib.abc.PathEntryFinder):
|
||||
path: str
|
||||
def __init__(self, path: str, *loader_details: Tuple[importlib.abc.Loader, List[str]]) -> None: ...
|
||||
@classmethod
|
||||
def path_hook(
|
||||
cls, *loader_details: Tuple[importlib.abc.Loader, List[str]]
|
||||
) -> Callable[[str], importlib.abc.PathEntryFinder]: ...
|
||||
|
||||
class SourceFileLoader(importlib.abc.FileLoader, importlib.abc.SourceLoader): ...
|
||||
class SourcelessFileLoader(importlib.abc.FileLoader, importlib.abc.SourceLoader): ...
|
||||
|
||||
class ExtensionFileLoader(importlib.abc.ExecutionLoader):
|
||||
def get_filename(self, fullname: str) -> importlib.abc._Path: ...
|
||||
def get_source(self, fullname: str) -> None: ...
|
||||
87
stdlib/importlib/metadata.pyi
Normal file
87
stdlib/importlib/metadata.pyi
Normal file
@@ -0,0 +1,87 @@
|
||||
import abc
|
||||
import os
|
||||
import pathlib
|
||||
import sys
|
||||
from email.message import Message
|
||||
from importlib.abc import MetaPathFinder
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, Iterable, List, NamedTuple, Optional, Tuple, Union, overload
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
class PackageNotFoundError(ModuleNotFoundError): ...
|
||||
class EntryPointBase(NamedTuple):
|
||||
name: str
|
||||
value: str
|
||||
group: str
|
||||
class EntryPoint(EntryPointBase):
|
||||
def load(self) -> Any: ... # Callable[[], Any] or an importable module
|
||||
@property
|
||||
def extras(self) -> List[str]: ...
|
||||
class PackagePath(pathlib.PurePosixPath):
|
||||
def read_text(self, encoding: str = ...) -> str: ...
|
||||
def read_binary(self) -> bytes: ...
|
||||
def locate(self) -> os.PathLike[str]: ...
|
||||
# The following attributes are not defined on PackagePath, but are dynamically added by Distribution.files:
|
||||
hash: Optional[FileHash]
|
||||
size: Optional[int]
|
||||
dist: Distribution
|
||||
class FileHash:
|
||||
mode: str
|
||||
value: str
|
||||
def __init__(self, spec: str) -> None: ...
|
||||
class Distribution:
|
||||
@abc.abstractmethod
|
||||
def read_text(self, filename: str) -> Optional[str]: ...
|
||||
@abc.abstractmethod
|
||||
def locate_file(self, path: Union[os.PathLike[str], str]) -> os.PathLike[str]: ...
|
||||
@classmethod
|
||||
def from_name(cls, name: str) -> Distribution: ...
|
||||
@overload
|
||||
@classmethod
|
||||
def discover(cls, *, context: DistributionFinder.Context) -> Iterable[Distribution]: ...
|
||||
@overload
|
||||
@classmethod
|
||||
def discover(
|
||||
cls, *, context: None = ..., name: Optional[str] = ..., path: List[str] = ..., **kwargs: Any
|
||||
) -> Iterable[Distribution]: ...
|
||||
@staticmethod
|
||||
def at(path: Union[str, os.PathLike[str]]) -> PathDistribution: ...
|
||||
@property
|
||||
def metadata(self) -> Message: ...
|
||||
@property
|
||||
def version(self) -> str: ...
|
||||
@property
|
||||
def entry_points(self) -> List[EntryPoint]: ...
|
||||
@property
|
||||
def files(self) -> Optional[List[PackagePath]]: ...
|
||||
@property
|
||||
def requires(self) -> Optional[List[str]]: ...
|
||||
class DistributionFinder(MetaPathFinder):
|
||||
class Context:
|
||||
name: Optional[str]
|
||||
def __init__(self, *, name: Optional[str] = ..., path: List[str] = ..., **kwargs: Any) -> None: ...
|
||||
@property
|
||||
def path(self) -> List[str]: ...
|
||||
@property
|
||||
def pattern(self) -> str: ...
|
||||
@abc.abstractmethod
|
||||
def find_distributions(self, context: DistributionFinder.Context = ...) -> Iterable[Distribution]: ...
|
||||
class MetadataPathFinder(DistributionFinder):
|
||||
@classmethod
|
||||
def find_distributions(cls, context: DistributionFinder.Context = ...) -> Iterable[PathDistribution]: ...
|
||||
class PathDistribution(Distribution):
|
||||
def __init__(self, path: Path) -> None: ...
|
||||
def read_text(self, filename: Union[str, os.PathLike[str]]) -> str: ...
|
||||
def locate_file(self, path: Union[str, os.PathLike[str]]) -> os.PathLike[str]: ...
|
||||
def distribution(distribution_name: str) -> Distribution: ...
|
||||
@overload
|
||||
def distributions(*, context: DistributionFinder.Context) -> Iterable[Distribution]: ...
|
||||
@overload
|
||||
def distributions(
|
||||
*, context: None = ..., name: Optional[str] = ..., path: List[str] = ..., **kwargs: Any
|
||||
) -> Iterable[Distribution]: ...
|
||||
def metadata(distribution_name: str) -> Message: ...
|
||||
def version(distribution_name: str) -> str: ...
|
||||
def entry_points() -> Dict[str, Tuple[EntryPoint, ...]]: ...
|
||||
def files(distribution_name: str) -> Optional[List[PackagePath]]: ...
|
||||
def requires(distribution_name: str) -> Optional[List[str]]: ...
|
||||
22
stdlib/importlib/resources.pyi
Normal file
22
stdlib/importlib/resources.pyi
Normal file
@@ -0,0 +1,22 @@
|
||||
import sys
|
||||
|
||||
# This is a >=3.7 module, so we conditionally include its source.
|
||||
if sys.version_info >= (3, 7):
|
||||
import os
|
||||
from pathlib import Path
|
||||
from types import ModuleType
|
||||
from typing import BinaryIO, ContextManager, Iterator, TextIO, Union
|
||||
|
||||
Package = Union[str, ModuleType]
|
||||
Resource = Union[str, os.PathLike]
|
||||
def open_binary(package: Package, resource: Resource) -> BinaryIO: ...
|
||||
def open_text(package: Package, resource: Resource, encoding: str = ..., errors: str = ...) -> TextIO: ...
|
||||
def read_binary(package: Package, resource: Resource) -> bytes: ...
|
||||
def read_text(package: Package, resource: Resource, encoding: str = ..., errors: str = ...) -> str: ...
|
||||
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: ...
|
||||
40
stdlib/importlib/util.pyi
Normal file
40
stdlib/importlib/util.pyi
Normal file
@@ -0,0 +1,40 @@
|
||||
import importlib.abc
|
||||
import importlib.machinery
|
||||
import os
|
||||
import types
|
||||
from typing import Any, Callable, List, Optional, Union
|
||||
|
||||
def module_for_loader(fxn: Callable[..., types.ModuleType]) -> Callable[..., types.ModuleType]: ...
|
||||
def set_loader(fxn: Callable[..., types.ModuleType]) -> Callable[..., types.ModuleType]: ...
|
||||
def set_package(fxn: Callable[..., types.ModuleType]) -> Callable[..., types.ModuleType]: ...
|
||||
def resolve_name(name: str, package: str) -> str: ...
|
||||
|
||||
MAGIC_NUMBER: bytes
|
||||
|
||||
def cache_from_source(path: str, debug_override: Optional[bool] = ..., *, optimization: Optional[Any] = ...) -> str: ...
|
||||
def source_from_cache(path: str) -> str: ...
|
||||
def decode_source(source_bytes: bytes) -> str: ...
|
||||
def find_spec(name: str, package: Optional[str] = ...) -> Optional[importlib.machinery.ModuleSpec]: ...
|
||||
def spec_from_loader(
|
||||
name: str,
|
||||
loader: Optional[importlib.abc.Loader],
|
||||
*,
|
||||
origin: Optional[str] = ...,
|
||||
loader_state: Optional[Any] = ...,
|
||||
is_package: Optional[bool] = ...,
|
||||
) -> importlib.machinery.ModuleSpec: ...
|
||||
def spec_from_file_location(
|
||||
name: str,
|
||||
location: Union[str, bytes, os.PathLike[str], os.PathLike[bytes]],
|
||||
*,
|
||||
loader: Optional[importlib.abc.Loader] = ...,
|
||||
submodule_search_locations: Optional[List[str]] = ...,
|
||||
) -> importlib.machinery.ModuleSpec: ...
|
||||
def module_from_spec(spec: importlib.machinery.ModuleSpec) -> types.ModuleType: ...
|
||||
|
||||
class LazyLoader(importlib.abc.Loader):
|
||||
def __init__(self, loader: importlib.abc.Loader) -> None: ...
|
||||
@classmethod
|
||||
def factory(cls, loader: importlib.abc.Loader) -> Callable[..., LazyLoader]: ...
|
||||
def create_module(self, spec: importlib.machinery.ModuleSpec) -> Optional[types.ModuleType]: ...
|
||||
def exec_module(self, module: types.ModuleType) -> None: ...
|
||||
Reference in New Issue
Block a user