-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.pyi
More file actions
349 lines (278 loc) · 9.93 KB
/
__init__.pyi
File metadata and controls
349 lines (278 loc) · 9.93 KB
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
import sys
import types
import typing
import typing_extensions
__lazy_modules__: list[str]
from collections.abc import Callable, Iterable
from types import MappingProxyType
if sys.version_info >= (3, 14):
import annotationlib
_py_type = annotationlib.ForwardRef | type | str
else:
_py_type = type | str
_CopiableMappings = dict[str, typing.Any] | MappingProxyType[str, typing.Any]
_T = typing.TypeVar("_T")
_FieldType = typing.TypeVar("_FieldType", bound=Field)
_gatherer_argtype = type | _CopiableMappings
_gatherer_returntype = tuple[dict[str, Field], dict[str, typing.Any]]
__version__: str
__version_tuple__: tuple[str | int, ...]
INTERNALS_DICT: str
META_GATHERER_NAME: str
GATHERED_DATA: str
@typing.type_check_only
class GetFieldsProtocol(typing.Protocol):
def __call__(self, cls: type, *, local: bool = ...) -> dict[str, Field]: ...
def get_fields(cls: type, *, local: bool = ...) -> dict[str, Field]: ...
def get_flags(cls: type) -> dict[str, bool]: ...
def get_methods(cls: type) -> types.MappingProxyType[str, MethodMaker]: ...
def get_generated_code(cls: type) -> dict[str, GeneratedCode]: ...
def print_generated_code(cls: type) -> None: ...
def build_completed(cls: type) -> bool: ...
def _get_inst_fields(inst: typing.Any) -> dict[str, typing.Any]: ...
class _NothingType:
def __init__(self, custom: str | None = ...) -> None: ...
def __repr__(self) -> str: ...
NOTHING: _NothingType
FIELD_NOTHING: _NothingType
class _KW_ONLY_META(type):
def __repr__(self) -> str: ...
class KW_ONLY(metaclass=_KW_ONLY_META): ...
# Stub Only Protocols
@typing.type_check_only
class _CodegenType(typing.Protocol):
def __call__(self, cls: type, funcname: str = ...) -> GeneratedCode: ...
@typing.type_check_only
class GathererProtocol(typing.Protocol, typing.Generic[_FieldType]):
def __call__(self, cls: _gatherer_argtype) -> tuple[dict[str, _FieldType], dict[str, typing.Any]]: ...
@typing.type_check_only
class AnnotationGathererProtocol(typing.Protocol, typing.Generic[_FieldType]):
def __call__(
self,
cls: _gatherer_argtype,
*,
cls_annotations: None | dict[str, typing.Any]
) -> tuple[dict[str, _FieldType], dict[str, typing.Any]]: ...
class GeneratedCode:
__slots__: tuple[str, ...]
source_code: str
globs: dict[str, typing.Any]
annotations: dict[str, typing.Any]
def __init__(
self,
source_code: str,
globs: dict[str, typing.Any],
annotations: dict[str, typing.Any] | None = ...,
) -> None: ...
def __repr__(self) -> str: ...
class MethodMaker:
funcname: str
code_generator: _CodegenType
def __init__(self, funcname: str, code_generator: _CodegenType) -> None: ...
def __repr__(self) -> str: ...
def __get__(self, instance, cls) -> Callable: ...
class _SignatureMaker:
def __get__(self, instance, cls=None) -> typing_extensions.Never: ...
signature_maker: _SignatureMaker
def get_init_generator(
null: _NothingType = NOTHING,
extra_code: None | list[str] = None
) -> _CodegenType: ...
def init_generator(cls: type, funcname: str="__init__") -> GeneratedCode: ...
def get_repr_generator(
recursion_safe: bool = False,
eval_safe: bool = False
) -> _CodegenType: ...
def repr_generator(cls: type, funcname: str = "__repr__") -> GeneratedCode: ...
def eq_generator(cls: type, funcname: str = "__eq__") -> GeneratedCode: ...
def get_order_generator(cls: type, funcname: str, *, operator: str) -> GeneratedCode: ...
def lt_generator(cls: type, funcname: str = ...) -> GeneratedCode: ...
def le_generator(cls: type, funcname: str = ...) -> GeneratedCode: ...
def gt_generator(cls: type, funcname: str = ...) -> GeneratedCode: ...
def ge_generator(cls: type, funcname: str = ...) -> GeneratedCode: ...
def replace_generator(cls: type, funcname: str = "__replace__") -> GeneratedCode: ...
def frozen_setattr_generator(cls: type, funcname: str = "__setattr__") -> GeneratedCode: ...
def frozen_delattr_generator(cls: type, funcname: str = "__delattr__") -> GeneratedCode: ...
def hash_generator(cls: type, funcname: str = ...) -> GeneratedCode: ...
init_maker: MethodMaker
repr_maker: MethodMaker
eq_maker: MethodMaker
lt_maker: MethodMaker
le_maker: MethodMaker
gt_maker: MethodMaker
ge_maker: MethodMaker
replace_maker: MethodMaker
frozen_setattr_maker: MethodMaker
frozen_delattr_maker: MethodMaker
hash_maker: MethodMaker
default_methods: frozenset[MethodMaker]
_TypeT = typing.TypeVar("_TypeT", bound=type)
def add_methods(
cls: type,
methods: Iterable[MethodMaker],
*,
internals: None | dict[str, typing.Any] = ...
) -> dict[str, MethodMaker]: ...
@typing.overload
def builder(
cls: _TypeT,
/,
*,
gatherer: GathererProtocol[Field],
methods: frozenset[MethodMaker] | set[MethodMaker],
flags: dict[str, bool] | None = None,
fix_signature: bool = ...,
field_getter: GetFieldsProtocol = ...,
) -> _TypeT: ...
@typing.overload
def builder(
cls: None = None,
/,
*,
gatherer: GathererProtocol[Field],
methods: frozenset[MethodMaker] | set[MethodMaker],
flags: dict[str, bool] | None = None,
fix_signature: bool = ...,
field_getter: GetFieldsProtocol = ...,
) -> Callable[[_TypeT], _TypeT]: ...
class SlotFields(dict):
...
class SlotMakerMeta(type):
def __new__(
cls: type[_TypeT],
name: str,
bases: tuple[type, ...],
ns: dict[str, typing.Any],
slots: bool = ...,
gatherer: GathererProtocol | None = ...,
ignore_annotations: bool | None = ...,
**kwargs: typing.Any,
) -> _TypeT: ...
# Only technically frozen under testing but we should *act* like they are frozen
@typing.dataclass_transform(field_specifiers=(Field,), frozen_default=True)
class Field(metaclass=SlotMakerMeta):
default: _NothingType | typing.Any
default_factory: _NothingType | typing.Any
type: _NothingType | _py_type
doc: None | str
init: bool
repr: bool
compare: bool
kw_only: bool
__slots__: dict[str, str]
__classbuilder_internals__: dict
__signature__: _SignatureMaker
def __init__(
self,
*,
default: _NothingType | typing.Any = ...,
default_factory: _NothingType | typing.Any = ...,
type: _NothingType | _py_type = ...,
doc: None | str = ...,
init: bool = ...,
repr: bool = ...,
compare: bool = ...,
kw_only: bool = ...,
) -> None: ...
def __init_subclass__(cls, frozen: bool = ..., ignore_annotations: bool = ...): ...
def __repr__(self) -> str: ...
def __eq__(self, other: Field | object) -> bool: ...
def __replace__(self, **kwargs) -> typing.Self: ...
def validate_field(self) -> None: ...
@classmethod
def from_field(cls, fld: Field, /, **kwargs: typing.Any) -> typing.Self: ...
# These types only exist because type[Field] doesn't seem to resolve correctly
# Technically they're wrong as `isinstance` gets used
_ReturnsField = Callable[..., Field]
@typing.type_check_only
class NoArgGathererProtocol(typing.Protocol):
def __call__(
self,
cls: _gatherer_argtype,
*,
cls_annotations: None | dict[str, typing.Any]
) -> tuple[dict[str, Field], dict[str, typing.Any]]: ...
@typing.type_check_only
class NoArgAnnotationGathererProtocol(typing.Protocol):
def __call__(
self,
cls: _gatherer_argtype,
*,
cls_annotations: None | dict[str, typing.Any]
) -> tuple[dict[str, Field], dict[str, typing.Any]]: ...
@typing.overload
def make_slot_gatherer(
field_type: _ReturnsField = ...,
) -> NoArgGathererProtocol: ...
@typing.overload
def make_slot_gatherer(
field_type: type[_FieldType],
) -> GathererProtocol[_FieldType]: ...
@typing.overload
def make_annotation_gatherer(
field_type: _ReturnsField = ...,
leave_default_values: bool = False,
) -> NoArgAnnotationGathererProtocol: ...
@typing.overload
def make_annotation_gatherer(
field_type: type[_FieldType],
leave_default_values: bool = False,
) -> AnnotationGathererProtocol[_FieldType]: ...
@typing.overload
def make_field_gatherer(
field_type: _ReturnsField = ...,
leave_default_values: bool = False,
) -> NoArgGathererProtocol: ...
@typing.overload
def make_field_gatherer(
field_type: type[_FieldType],
leave_default_values: bool = False,
) -> GathererProtocol[_FieldType]: ...
@typing.overload
def make_unified_gatherer(
field_type: _ReturnsField = ...,
leave_default_values: bool = ...,
) -> NoArgGathererProtocol: ...
@typing.overload
def make_unified_gatherer(
field_type: type[_FieldType],
leave_default_values: bool = ...,
) -> GathererProtocol[_FieldType]: ...
def slot_gatherer(cls_or_ns: type | _CopiableMappings) -> _gatherer_returntype: ...
def annotation_gatherer(
cls_or_ns: type | _CopiableMappings,
*,
cls_annotations: None | dict[str, typing.Any] = ...
) -> _gatherer_returntype: ...
def unified_gatherer(cls_or_ns: type | _CopiableMappings) -> _gatherer_returntype: ...
def check_argument_order(cls: type) -> None: ...
def replace(obj: _T, /, **changes: typing.Any) -> _T: ...
@typing.overload
def slotclass(
cls: _TypeT,
/,
*,
methods: frozenset[MethodMaker] | set[MethodMaker] = default_methods,
syntax_check: bool = True
) -> _TypeT: ...
@typing.overload
def slotclass(
cls: None = None,
/,
*,
methods: frozenset[MethodMaker] | set[MethodMaker] = default_methods,
syntax_check: bool = True
) -> Callable[[_TypeT], _TypeT]: ...
_gatherer_type = Callable[[type | _CopiableMappings], tuple[dict[str, Field], dict[str, typing.Any]]]
class GatheredFields:
__slots__: tuple[str, ...]
fields: dict[str, Field]
modifications: dict[str, typing.Any]
def __init__(
self,
fields: dict[str, Field],
modifications: dict[str, typing.Any]
) -> None: ...
def __repr__(self) -> str: ...
def __eq__(self, other) -> bool: ...
def __call__(self, cls_dict: type | dict[str, typing.Any]) -> tuple[dict[str, Field], dict[str, typing.Any]]: ...