cython

Форк
0
/
Shadow.pyi 
282 строки · 7.5 Кб
1
import dataclasses as dataclasses
2
from builtins import (int as py_int, float as py_float,
3
                      bool as py_bool, str as py_str, complex as py_complex)
4
from types import TracebackType
5
from typing import Any, Iterable, Sequence, Optional, Type, TypeVar, Generic, Callable, overload
6

7
# Type checkers assume typing_extensions is always present
8
from typing_extensions import Literal, ParamSpec, overload, final as final
9

10
# Normally all imports aren't exported in stub files but we can explicitly expose
11
# imports by using import ... as ... (with the same name) which was done for
12
# dataclasses and the final decorator.
13

14
__version__: str
15

16
# Predefined types
17

18
int = py_int
19
long = py_int
20
longlong = py_int
21
short = py_int
22
char = py_int
23

24
sint = py_int
25
slong = py_int
26
slonglong = py_int
27
sshort = py_int
28
schar = py_int
29

30
uint = py_int
31
ulong = py_int
32
ulonglong = py_int
33
ushort = py_int
34
uchar = py_int
35

36
size_t = py_int
37
Py_ssize_t = py_int
38

39
Py_UCS4 = py_int | str
40
Py_UNICODE = py_int | str
41

42
float = py_float
43
double = py_float
44
longdouble = py_float
45

46
complex = py_complex
47
floatcomplex = py_complex
48
doublecomplex = py_complex
49
longdoublecomplex = py_complex
50

51
bint = py_bool
52
void = Type[None]
53
basestring = py_str
54
unicode = py_str
55

56
gs: dict[str, Any]  # Should match the return type of globals()
57
compiled: bool
58

59

60
_T = TypeVar('_T')
61
_P = ParamSpec('_P')
62
_C = TypeVar('_C', bound='Callable')
63
_TypeT = TypeVar('_TypeT', bound='Type')
64
_Decorator = Callable[[_C], _C]
65

66

67
_func_deco: _Decorator
68

69
cfunc = ccall = compile = _func_deco
70

71
def locals(**kwargs: Any) -> _Decorator: ...
72

73
def _class_deco(__cls: _TypeT) -> _TypeT: ...
74

75
cclass = internal = c_api_binop_methods = type_version_tag = no_gc_clear = no_gc = _class_deco
76

77
# May be a bit hard to read but essentially means:
78
# > Returns a callable that takes another callable with these parameters and *some*
79
# > return value, then returns another callable with the same parameters but
80
# > the return type is the previous 'type' parameter.
81
# On Python 3.5, the latest version of Mypy available is 0.910 which doesn't understand ParamSpec
82
def returns(__type: Type[_T]) -> Callable[[Callable[_P, object]], Callable[_P, _T]]: ...  # type: ignore
83

84
def exceptval(__val: Any, *, check: bool = False) -> _Decorator: ...
85

86
class _EmptyDecoratorAndManager(object):
87
    @overload
88
    def __call__(self, __val: bool) -> _Decorator: ...
89

90
    @overload
91
    def __call__(self, __func: _C) -> _C: ...
92

93
    def __enter__(self) -> None: ...
94

95
    def __exit__(
96
        self,
97
        exc_type: Optional[Type[BaseException]],
98
        exc: Optional[BaseException],
99
        tb: Optional[TracebackType]
100
    ) -> None: ...
101
_empty_decorator_and_manager: _EmptyDecoratorAndManager
102

103
@overload
104
def _compiler_directive(__func: _C) -> _C: ...
105

106
@overload
107
def _compiler_directive(__val: bool = ...) -> _Decorator: ...
108

109
# These all come from 'Compiler directives' on Source Files and Compilation.
110
# The following directives are missing as they need to be global:
111
# - annotation_typing
112
# - c_string_type
113
# - c_string_encoding
114
# Note that c_api_binop_methods and type_version_tag is defined above.
115

116
boundscheck = wraparound = initializedcheck = nonecheck = cdivision = \
117
    cdivision_warnings = profile = linetrace = infer_types = \
118
    emit_code_comments = _empty_decorator_and_manager
119

120
binding = embedsignature = always_allow_keywords = unraisable_tracebacks = \
121
    iterable_coroutine = cpp_locals = _compiler_directive
122

123
# overflowcheck() has to be specialized because there is also overflowcheck.fold
124
class _OverflowcheckClass:
125
    def __call__(self, __val: bool = ...) -> _Decorator: ...
126

127
    def fold(self, __val: bool = ...) -> _Decorator: ...
128

129
overflowcheck = _OverflowcheckClass()
130

131
class optimize:
132
    @staticmethod
133
    def use_switch(__val: bool = ...) -> _Decorator: ...
134

135
    @staticmethod
136
    def unpack_method_calls(__val: bool = ...) -> _Decorator: ...
137

138
class warn:
139
    @staticmethod
140
    def undeclared(__val: bool = ...) -> _Decorator: ...
141

142
    @staticmethod
143
    def unreachable(__val: bool = ...) -> _Decorator: ...
144

145
    @staticmethod
146
    def maybe_uninitialized(__val: bool = ...) -> _Decorator: ...
147

148
    @staticmethod
149
    def unused(__val: bool = ...) -> _Decorator: ...
150

151
    @staticmethod
152
    def unused_argument(__val: bool = ...) -> _Decorator: ...
153

154
    @staticmethod
155
    def multiple_declarators(__val: bool = ...) -> _Decorator: ...
156

157
@overload
158
def inline(__func: _C) -> _C: ...
159

160
@overload
161
def inline(__code: str, *, get_type: Callable[[object, object], str] = ..., lib_dir: str = ...,
162
           cython_include_dirs: Iterable[str] = ..., cython_compiler_directives: Iterable[str] = ...,
163
           force: bool = ..., quiet: bool = ..., locals: dict[str, str] = ..., globals: dict[str, str] = ...,
164
           language_level: str = ...) -> Any: ...
165

166
def cdiv(__a: int, __b: int) -> int: ...
167

168
def cmod(__a: int, __b: int) -> int: ...
169

170
@overload
171
def cast(__t: Type[_T], __value: Any) -> _T: ...
172

173
# On Python 3.5, the latest version of Mypy available is 0.910 which doesn't understand ParamSpec
174
@overload
175
def cast(__t: Callable[_P, _T], *args: _P.args, **kwargs: _P.kwargs) -> _T: ...  # type: ignore
176

177
def sizeof(__obj: object) -> int: ...
178

179
def typeof(__obj: object) -> str: ...
180

181
def address(__obj: object) -> PointerType: ...
182

183

184
@overload
185
def declare(
186
    t: Optional[Callable[..., _T]] = ...,
187
    value: Any = ...,
188
) -> _T:
189
    ...
190

191
# This one is for attributes, they cannot have initializers through cython.declare() currently.
192
@overload
193
def declare(
194
    t: Callable[..., _T],
195
    *,
196
    visibility: Literal['public', 'readonly', 'private'] = ...,
197
) -> _T:
198
    ...
199

200
@overload
201
def declare(**kwargs: type) -> None: ...
202

203

204
class _nogil:
205
    @overload
206
    def __call__(self, __val: bool) -> _Decorator: ...
207

208
    @overload
209
    def __call__(self, __func: _C) -> _C: ...
210

211
    @overload
212
    def __call__(self) -> '_nogil': ...
213

214
    def __enter__(self) -> None: ...
215

216
    def __exit__(
217
        self,
218
        exc_type: Optional[Type[BaseException]],
219
        exc: Optional[BaseException],
220
        tb: Optional[TracebackType]
221
    ) -> None: ...
222

223
nogil = gil = _nogil
224

225

226
class _ArrayType(Generic[_T]):
227
    is_array: bool
228
    subtypes: Sequence[str]
229
    dtype: _T
230
    ndim: int
231
    is_c_contig: bool
232
    is_f_contig: bool
233
    inner_contig: bool
234
    broadcasting: Any
235

236
    # broadcasting is not used, so it's not clear about its type
237
    def __init__(self, dtype: _T, ndim: int, is_c_contig: bool = ...,
238
                 is_f_contig: bool = ..., inner_contig: bool = ...,
239
                 broadcasting: Any = ...) -> None: ...
240
    def __repr__(self) -> str: ...
241

242

243
class CythonTypeObject(object):
244
    ...
245

246
class CythonType(CythonTypeObject):
247
    ...
248

249
class PointerType(CythonType, Generic[_T]):
250
    def __init__(
251
        self,
252
        value: Optional[ArrayType[_T] | PointerType[_T] | list[_T] | int] = ...
253
    ) -> None: ...
254
    def __getitem__(self, ix: int) -> _T: ...
255
    def __setitem__(self, ix: int, value: _T) -> None: ...
256
    def __eq__(self, value: object) -> bool: ...
257
    def __repr__(self) -> str: ...
258

259
class ArrayType(PointerType[_T]):
260
    def __init__(self) -> None: ...
261

262
def index_type(
263
    base_type: _T, item: tuple | slice | int) -> _ArrayType[_T]: ...
264

265
def pointer(basetype: _T) -> Type[PointerType[_T]]: ...
266

267
def array(basetype: _T, n: int) -> Type[ArrayType[_T]]: ...
268

269
def struct(**members: type) -> Type[Any]: ...
270

271
def union(**members: type) -> Type[Any]: ...
272

273
def fused_type(*args: Any) -> Type[Any]: ...
274

275

276
class typedef(CythonType, Generic[_T]):
277
    name: str
278

279
    def __init__(self, type: _T, name: Optional[str] = ...) -> None: ...
280
    def __call__(self, *arg: Any) -> _T: ...
281
    def __repr__(self) -> str: ...
282
    __getitem__ = index_type
283

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.