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
7
# Type checkers assume typing_extensions is always present
8
from typing_extensions import Literal, ParamSpec, overload, final as final
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.
40
Py_UNICODE = py_int | str
47
floatcomplex = py_complex
48
doublecomplex = py_complex
49
longdoublecomplex = py_complex
56
gs: dict[str, Any] # Should match the return type of globals()
62
_C = TypeVar('_C', bound='Callable')
63
_TypeT = TypeVar('_TypeT', bound='Type')
64
_Decorator = Callable[[_C], _C]
69
cfunc = ccall = compile = _func_deco
71
def locals(**kwargs: Any) -> _Decorator: ...
73
def _class_deco(__cls: _TypeT) -> _TypeT: ...
75
cclass = internal = c_api_binop_methods = type_version_tag = no_gc_clear = no_gc = _class_deco
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
84
def exceptval(__val: Any, *, check: bool = False) -> _Decorator: ...
86
class _EmptyDecoratorAndManager(object):
88
def __call__(self, __val: bool) -> _Decorator: ...
91
def __call__(self, __func: _C) -> _C: ...
93
def __enter__(self) -> None: ...
97
exc_type: Optional[Type[BaseException]],
98
exc: Optional[BaseException],
99
tb: Optional[TracebackType]
101
_empty_decorator_and_manager: _EmptyDecoratorAndManager
104
def _compiler_directive(__func: _C) -> _C: ...
107
def _compiler_directive(__val: bool = ...) -> _Decorator: ...
109
# These all come from 'Compiler directives' on Source Files and Compilation.
110
# The following directives are missing as they need to be global:
114
# Note that c_api_binop_methods and type_version_tag is defined above.
116
boundscheck = wraparound = initializedcheck = nonecheck = cdivision = \
117
cdivision_warnings = profile = linetrace = infer_types = \
118
emit_code_comments = _empty_decorator_and_manager
120
binding = embedsignature = always_allow_keywords = unraisable_tracebacks = \
121
iterable_coroutine = cpp_locals = _compiler_directive
123
# overflowcheck() has to be specialized because there is also overflowcheck.fold
124
class _OverflowcheckClass:
125
def __call__(self, __val: bool = ...) -> _Decorator: ...
127
def fold(self, __val: bool = ...) -> _Decorator: ...
129
overflowcheck = _OverflowcheckClass()
133
def use_switch(__val: bool = ...) -> _Decorator: ...
136
def unpack_method_calls(__val: bool = ...) -> _Decorator: ...
140
def undeclared(__val: bool = ...) -> _Decorator: ...
143
def unreachable(__val: bool = ...) -> _Decorator: ...
146
def maybe_uninitialized(__val: bool = ...) -> _Decorator: ...
149
def unused(__val: bool = ...) -> _Decorator: ...
152
def unused_argument(__val: bool = ...) -> _Decorator: ...
155
def multiple_declarators(__val: bool = ...) -> _Decorator: ...
158
def inline(__func: _C) -> _C: ...
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: ...
166
def cdiv(__a: int, __b: int) -> int: ...
168
def cmod(__a: int, __b: int) -> int: ...
171
def cast(__t: Type[_T], __value: Any) -> _T: ...
173
# On Python 3.5, the latest version of Mypy available is 0.910 which doesn't understand ParamSpec
175
def cast(__t: Callable[_P, _T], *args: _P.args, **kwargs: _P.kwargs) -> _T: ... # type: ignore
177
def sizeof(__obj: object) -> int: ...
179
def typeof(__obj: object) -> str: ...
181
def address(__obj: object) -> PointerType: ...
186
t: Optional[Callable[..., _T]] = ...,
191
# This one is for attributes, they cannot have initializers through cython.declare() currently.
194
t: Callable[..., _T],
196
visibility: Literal['public', 'readonly', 'private'] = ...,
201
def declare(**kwargs: type) -> None: ...
206
def __call__(self, __val: bool) -> _Decorator: ...
209
def __call__(self, __func: _C) -> _C: ...
212
def __call__(self) -> '_nogil': ...
214
def __enter__(self) -> None: ...
218
exc_type: Optional[Type[BaseException]],
219
exc: Optional[BaseException],
220
tb: Optional[TracebackType]
226
class _ArrayType(Generic[_T]):
228
subtypes: Sequence[str]
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: ...
243
class CythonTypeObject(object):
246
class CythonType(CythonTypeObject):
249
class PointerType(CythonType, Generic[_T]):
252
value: Optional[ArrayType[_T] | PointerType[_T] | list[_T] | int] = ...
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: ...
259
class ArrayType(PointerType[_T]):
260
def __init__(self) -> None: ...
263
base_type: _T, item: tuple | slice | int) -> _ArrayType[_T]: ...
265
def pointer(basetype: _T) -> Type[PointerType[_T]]: ...
267
def array(basetype: _T, n: int) -> Type[ArrayType[_T]]: ...
269
def struct(**members: type) -> Type[Any]: ...
271
def union(**members: type) -> Type[Any]: ...
273
def fused_type(*args: Any) -> Type[Any]: ...
276
class typedef(CythonType, Generic[_T]):
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