massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-pyright / node_modules / pyright / dist / typeshed-fallback / stdlib / importlib / abc.pyi
1 import sys
2 import types
3 from _typeshed import (
4     OpenBinaryMode,
5     OpenBinaryModeReading,
6     OpenBinaryModeUpdating,
7     OpenBinaryModeWriting,
8     OpenTextMode,
9     StrOrBytesPath,
10     StrPath,
11 )
12 from abc import ABCMeta, abstractmethod
13 from importlib.machinery import ModuleSpec
14 from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper
15 from typing import IO, Any, BinaryIO, Iterator, Mapping, Protocol, Sequence, Union, overload
16 from typing_extensions import Literal, runtime_checkable
17
18 _Path = Union[bytes, str]
19
20 class Finder(metaclass=ABCMeta): ...
21
22 class ResourceLoader(Loader):
23     @abstractmethod
24     def get_data(self, path: _Path) -> bytes: ...
25
26 class InspectLoader(Loader):
27     def is_package(self, fullname: str) -> bool: ...
28     def get_code(self, fullname: str) -> types.CodeType | None: ...
29     def load_module(self, fullname: str) -> types.ModuleType: ...
30     @abstractmethod
31     def get_source(self, fullname: str) -> str | None: ...
32     def exec_module(self, module: types.ModuleType) -> None: ...
33     @staticmethod
34     def source_to_code(data: bytes | str, path: str = ...) -> types.CodeType: ...
35
36 class ExecutionLoader(InspectLoader):
37     @abstractmethod
38     def get_filename(self, fullname: str) -> _Path: ...
39     def get_code(self, fullname: str) -> types.CodeType | None: ...
40
41 class SourceLoader(ResourceLoader, ExecutionLoader, metaclass=ABCMeta):
42     def path_mtime(self, path: _Path) -> float: ...
43     def set_data(self, path: _Path, data: bytes) -> None: ...
44     def get_source(self, fullname: str) -> str | None: ...
45     def path_stats(self, path: _Path) -> Mapping[str, Any]: ...
46
47 # Please keep in sync with sys._MetaPathFinder
48 class MetaPathFinder(Finder):
49     def find_module(self, fullname: str, path: Sequence[_Path] | None) -> Loader | None: ...
50     def invalidate_caches(self) -> None: ...
51     # Not defined on the actual class, but expected to exist.
52     def find_spec(
53         self, fullname: str, path: Sequence[_Path] | None, target: types.ModuleType | None = ...
54     ) -> ModuleSpec | None: ...
55
56 class PathEntryFinder(Finder):
57     def find_module(self, fullname: str) -> Loader | None: ...
58     def find_loader(self, fullname: str) -> tuple[Loader | None, Sequence[_Path]]: ...
59     def invalidate_caches(self) -> None: ...
60     # Not defined on the actual class, but expected to exist.
61     def find_spec(self, fullname: str, target: types.ModuleType | None = ...) -> ModuleSpec | None: ...
62
63 class Loader(metaclass=ABCMeta):
64     def load_module(self, fullname: str) -> types.ModuleType: ...
65     def module_repr(self, module: types.ModuleType) -> str: ...
66     def create_module(self, spec: ModuleSpec) -> types.ModuleType | None: ...
67     # Not defined on the actual class for backwards-compatibility reasons,
68     # but expected in new code.
69     def exec_module(self, module: types.ModuleType) -> None: ...
70
71 class _LoaderProtocol(Protocol):
72     def load_module(self, fullname: str) -> types.ModuleType: ...
73
74 class FileLoader(ResourceLoader, ExecutionLoader, metaclass=ABCMeta):
75     name: str
76     path: _Path
77     def __init__(self, fullname: str, path: _Path) -> None: ...
78     def get_data(self, path: _Path) -> bytes: ...
79     def get_filename(self, name: str | None = ...) -> _Path: ...
80     def load_module(self, name: str | None = ...) -> types.ModuleType: ...
81
82 if sys.version_info >= (3, 7):
83     class ResourceReader(metaclass=ABCMeta):
84         @abstractmethod
85         def open_resource(self, resource: StrOrBytesPath) -> IO[bytes]: ...
86         @abstractmethod
87         def resource_path(self, resource: StrOrBytesPath) -> str: ...
88         @abstractmethod
89         def is_resource(self, name: str) -> bool: ...
90         @abstractmethod
91         def contents(self) -> Iterator[str]: ...
92
93 if sys.version_info >= (3, 9):
94     @runtime_checkable
95     class Traversable(Protocol):
96         @abstractmethod
97         def is_dir(self) -> bool: ...
98         @abstractmethod
99         def is_file(self) -> bool: ...
100         @abstractmethod
101         def iterdir(self) -> Iterator[Traversable]: ...
102         @abstractmethod
103         def joinpath(self, child: StrPath) -> Traversable: ...
104         # The .open method comes from pathlib.pyi and should be kept in sync.
105         @overload
106         @abstractmethod
107         def open(
108             self,
109             mode: OpenTextMode = ...,
110             buffering: int = ...,
111             encoding: str | None = ...,
112             errors: str | None = ...,
113             newline: str | None = ...,
114         ) -> TextIOWrapper: ...
115         # Unbuffered binary mode: returns a FileIO
116         @overload
117         @abstractmethod
118         def open(
119             self, mode: OpenBinaryMode, buffering: Literal[0], encoding: None = ..., errors: None = ..., newline: None = ...
120         ) -> FileIO: ...
121         # Buffering is on: return BufferedRandom, BufferedReader, or BufferedWriter
122         @overload
123         @abstractmethod
124         def open(
125             self,
126             mode: OpenBinaryModeUpdating,
127             buffering: Literal[-1, 1] = ...,
128             encoding: None = ...,
129             errors: None = ...,
130             newline: None = ...,
131         ) -> BufferedRandom: ...
132         @overload
133         @abstractmethod
134         def open(
135             self,
136             mode: OpenBinaryModeWriting,
137             buffering: Literal[-1, 1] = ...,
138             encoding: None = ...,
139             errors: None = ...,
140             newline: None = ...,
141         ) -> BufferedWriter: ...
142         @overload
143         @abstractmethod
144         def open(
145             self,
146             mode: OpenBinaryModeReading,
147             buffering: Literal[-1, 1] = ...,
148             encoding: None = ...,
149             errors: None = ...,
150             newline: None = ...,
151         ) -> BufferedReader: ...
152         # Buffering cannot be determined: fall back to BinaryIO
153         @overload
154         @abstractmethod
155         def open(
156             self, mode: OpenBinaryMode, buffering: int, encoding: None = ..., errors: None = ..., newline: None = ...
157         ) -> BinaryIO: ...
158         # Fallback if mode is not specified
159         @overload
160         @abstractmethod
161         def open(
162             self, mode: str, buffering: int = ..., encoding: str | None = ..., errors: str | None = ..., newline: str | None = ...
163         ) -> IO[Any]: ...
164         @property
165         def name(self) -> str: ...
166         @abstractmethod
167         def __truediv__(self, key: StrPath) -> Traversable: ...
168         @abstractmethod
169         def read_bytes(self) -> bytes: ...
170         @abstractmethod
171         def read_text(self, encoding: str | None = ...) -> str: ...