/
__init__.pyi
285 lines (251 loc) · 9.07 KB
/
__init__.pyi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
import abc
import pathlib
import sys
from _collections_abc import dict_keys, dict_values
from _typeshed import StrPath
from collections.abc import Iterable, Iterator, Mapping
from email.message import Message
from importlib.abc import MetaPathFinder
from os import PathLike
from pathlib import Path
from re import Pattern
from typing import Any, ClassVar, Generic, NamedTuple, TypeVar, overload
from typing_extensions import Self, TypeAlias
_T = TypeVar("_T")
_KT = TypeVar("_KT")
_VT = TypeVar("_VT")
__all__ = [
"Distribution",
"DistributionFinder",
"PackageNotFoundError",
"distribution",
"distributions",
"entry_points",
"files",
"metadata",
"requires",
"version",
]
if sys.version_info >= (3, 10):
__all__ += ["PackageMetadata", "packages_distributions"]
if sys.version_info >= (3, 10):
from importlib.metadata._meta import PackageMetadata as PackageMetadata, SimplePath
def packages_distributions() -> Mapping[str, list[str]]: ...
if sys.version_info >= (3, 12):
# It's generic but shouldn't be
_SimplePath: TypeAlias = SimplePath[Any]
else:
_SimplePath: TypeAlias = SimplePath
else:
_SimplePath: TypeAlias = Path
class PackageNotFoundError(ModuleNotFoundError):
@property
def name(self) -> str: ... # type: ignore[override]
if sys.version_info >= (3, 11):
class DeprecatedTuple:
def __getitem__(self, item: int) -> str: ...
_EntryPointBase = DeprecatedTuple
else:
class _EntryPointBase(NamedTuple):
name: str
value: str
group: str
class EntryPoint(_EntryPointBase):
pattern: ClassVar[Pattern[str]]
if sys.version_info >= (3, 11):
name: str
value: str
group: str
def __init__(self, name: str, value: str, group: str) -> None: ...
def load(self) -> Any: ... # Callable[[], Any] or an importable module
@property
def extras(self) -> list[str]: ...
if sys.version_info >= (3, 9):
@property
def module(self) -> str: ...
@property
def attr(self) -> str: ...
if sys.version_info >= (3, 10):
dist: ClassVar[Distribution | None]
def matches(
self,
*,
name: str = ...,
value: str = ...,
group: str = ...,
module: str = ...,
attr: str = ...,
extras: list[str] = ...,
) -> bool: ... # undocumented
def __hash__(self) -> int: ...
def __eq__(self, other: object) -> bool: ...
if sys.version_info >= (3, 11):
def __lt__(self, other: object) -> bool: ...
if sys.version_info < (3, 12):
def __iter__(self) -> Iterator[Any]: ... # result of iter((str, Self)), really
if sys.version_info >= (3, 12):
class EntryPoints(tuple[EntryPoint, ...]):
def __getitem__(self, name: str) -> EntryPoint: ... # type: ignore[override]
def select(
self,
*,
name: str = ...,
value: str = ...,
group: str = ...,
module: str = ...,
attr: str = ...,
extras: list[str] = ...,
) -> EntryPoints: ...
@property
def names(self) -> set[str]: ...
@property
def groups(self) -> set[str]: ...
elif sys.version_info >= (3, 10):
class DeprecatedList(list[_T]): ...
class EntryPoints(DeprecatedList[EntryPoint]): # use as list is deprecated since 3.10
# int argument is deprecated since 3.10
def __getitem__(self, name: int | str) -> EntryPoint: ... # type: ignore[override]
def select(
self,
*,
name: str = ...,
value: str = ...,
group: str = ...,
module: str = ...,
attr: str = ...,
extras: list[str] = ...,
) -> EntryPoints: ...
@property
def names(self) -> set[str]: ...
@property
def groups(self) -> set[str]: ...
if sys.version_info >= (3, 10) and sys.version_info < (3, 12):
class Deprecated(Generic[_KT, _VT]):
def __getitem__(self, name: _KT) -> _VT: ...
@overload
def get(self, name: _KT) -> _VT | None: ...
@overload
def get(self, name: _KT, default: _T) -> _VT | _T: ...
def __iter__(self) -> Iterator[_KT]: ...
def __contains__(self, *args: object) -> bool: ...
def keys(self) -> dict_keys[_KT, _VT]: ...
def values(self) -> dict_values[_KT, _VT]: ...
class SelectableGroups(Deprecated[str, EntryPoints], dict[str, EntryPoints]): # use as dict is deprecated since 3.10
@classmethod
def load(cls, eps: Iterable[EntryPoint]) -> Self: ...
@property
def groups(self) -> set[str]: ...
@property
def names(self) -> set[str]: ...
@overload
def select(self) -> Self: ... # type: ignore[misc]
@overload
def select(
self,
*,
name: str = ...,
value: str = ...,
group: str = ...,
module: str = ...,
attr: str = ...,
extras: list[str] = ...,
) -> EntryPoints: ...
class PackagePath(pathlib.PurePosixPath):
def read_text(self, encoding: str = "utf-8") -> str: ...
def read_binary(self) -> bytes: ...
def locate(self) -> PathLike[str]: ...
# The following attributes are not defined on PackagePath, but are dynamically added by Distribution.files:
hash: FileHash | None
size: int | None
dist: Distribution
class FileHash:
mode: str
value: str
def __init__(self, spec: str) -> None: ...
if sys.version_info >= (3, 12):
class DeprecatedNonAbstract: ...
_distribution_parent = DeprecatedNonAbstract
else:
_distribution_parent = object
class Distribution(_distribution_parent):
@abc.abstractmethod
def read_text(self, filename: str) -> str | None: ...
@abc.abstractmethod
def locate_file(self, path: StrPath) -> _SimplePath: ...
@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 = None, name: str | None = ..., path: list[str] = ..., **kwargs: Any
) -> Iterable[Distribution]: ...
@staticmethod
def at(path: StrPath) -> PathDistribution: ...
if sys.version_info >= (3, 10):
@property
def metadata(self) -> PackageMetadata: ...
@property
def entry_points(self) -> EntryPoints: ...
else:
@property
def metadata(self) -> Message: ...
@property
def entry_points(self) -> list[EntryPoint]: ...
@property
def version(self) -> str: ...
@property
def files(self) -> list[PackagePath] | None: ...
@property
def requires(self) -> list[str] | None: ...
if sys.version_info >= (3, 10):
@property
def name(self) -> str: ...
class DistributionFinder(MetaPathFinder):
class Context:
name: str | None
def __init__(self, *, name: str | None = ..., path: list[str] = ..., **kwargs: Any) -> None: ...
@property
def path(self) -> list[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]: ...
if sys.version_info >= (3, 10):
# Yes, this is an instance method that has a parameter named "cls"
def invalidate_caches(cls) -> None: ...
class PathDistribution(Distribution):
_path: _SimplePath
def __init__(self, path: _SimplePath) -> None: ...
def read_text(self, filename: StrPath) -> str | None: ...
def locate_file(self, path: StrPath) -> _SimplePath: ...
def distribution(distribution_name: str) -> Distribution: ...
@overload
def distributions(*, context: DistributionFinder.Context) -> Iterable[Distribution]: ...
@overload
def distributions(
*, context: None = None, name: str | None = ..., path: list[str] = ..., **kwargs: Any
) -> Iterable[Distribution]: ...
if sys.version_info >= (3, 10):
def metadata(distribution_name: str) -> PackageMetadata: ...
else:
def metadata(distribution_name: str) -> Message: ...
if sys.version_info >= (3, 12):
def entry_points(
*, name: str = ..., value: str = ..., group: str = ..., module: str = ..., attr: str = ..., extras: list[str] = ...
) -> EntryPoints: ...
elif sys.version_info >= (3, 10):
@overload
def entry_points() -> SelectableGroups: ... # type: ignore[overload-overlap]
@overload
def entry_points(
*, name: str = ..., value: str = ..., group: str = ..., module: str = ..., attr: str = ..., extras: list[str] = ...
) -> EntryPoints: ...
else:
def entry_points() -> dict[str, list[EntryPoint]]: ...
def version(distribution_name: str) -> str: ...
def files(distribution_name: str) -> list[PackagePath] | None: ...
def requires(distribution_name: str) -> list[str] | None: ...