diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index 668861ee5..3f7938823 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -36,6 +36,7 @@ "stubs/beautifulsoup4", "stubs/braintree", "stubs/caldav", + "stubs/cffi", "stubs/commonmark", "stubs/cryptography", "stubs/dateparser", diff --git a/stubs/cffi/@tests/stubtest_allowlist.txt b/stubs/cffi/@tests/stubtest_allowlist.txt new file mode 100644 index 000000000..2fa3441d5 --- /dev/null +++ b/stubs/cffi/@tests/stubtest_allowlist.txt @@ -0,0 +1,20 @@ +# technically exists on all OSs, but crashes on all but windows +cffi.(api.)?FFI.getwinerror + +# added dynamically and not detected by stubtest +cffi.(api.)?FFI.CData +cffi.(api.)?FFI.CType +cffi.(api.)?FFI.buffer + +# Exists at runtime, but missing from stubs +cffi.vengine_cpy.__warningregistry__ + +# Alias to io.StringIO, which has the same allowlist +cffi.recompiler.NativeIO.seek +cffi.recompiler.NativeIO.truncate +cffi.verifier.NativeIO.seek +cffi.verifier.NativeIO.truncate + +# Unnecessary re-exports +cffi.cparser.COMMON_TYPES +cffi.verifier.__version_verifier_modules__ \ No newline at end of file diff --git a/stubs/cffi/METADATA.toml b/stubs/cffi/METADATA.toml new file mode 100644 index 000000000..0857c7852 --- /dev/null +++ b/stubs/cffi/METADATA.toml @@ -0,0 +1,4 @@ +version = "1.15.*" + +[tool.stubtest] +ignore_missing_stub = false diff --git a/stubs/cffi/_cffi_backend.pyi b/stubs/cffi/_cffi_backend.pyi new file mode 100644 index 000000000..31dd329b5 --- /dev/null +++ b/stubs/cffi/_cffi_backend.pyi @@ -0,0 +1,265 @@ +import sys +import types +from _typeshed import Incomplete, ReadableBuffer, WriteableBuffer +from collections.abc import Callable, Hashable +from typing import Any, ClassVar, Protocol, TypeVar, overload +from typing_extensions import Literal, TypeAlias, final + +_T = TypeVar("_T") + +class _Allocator(Protocol): + def __call__(self, cdecl: str | CType, init: Any = ...) -> _CDataBase: ... + +__version__: str + +FFI_CDECL: int +FFI_DEFAULT_ABI: int +RTLD_GLOBAL: int +RTLD_LAZY: int +RTLD_LOCAL: int +RTLD_NOW: int +if sys.platform != "win32": + RTLD_DEEPBIND: int + RTLD_NODELETE: int + RTLD_NOLOAD: int + +@final +class CField: + bitshift: Incomplete + bitsize: Incomplete + flags: Incomplete + offset: Incomplete + type: Incomplete + +@final +class CLibrary: + def close_lib(self, *args, **kwargs): ... + def load_function(self, *args, **kwargs): ... + def read_variable(self, *args, **kwargs): ... + def write_variable(self, *args, **kwargs): ... + +@final +class CType: + abi: Incomplete + args: Incomplete + cname: Incomplete + elements: Incomplete + ellipsis: Incomplete + fields: Incomplete + item: Incomplete + kind: Incomplete + length: Incomplete + relements: Incomplete + result: Incomplete + def __dir__(self): ... + +@final +class Lib: + def __dir__(self): ... + +@final +class _CDataBase: + __name__: ClassVar[str] + def __add__(self, other): ... + def __bool__(self): ... + def __call__(self, *args, **kwargs): ... + def __complex__(self): ... + def __delitem__(self, other): ... + def __dir__(self): ... + def __enter__(self): ... + def __eq__(self, other): ... + def __exit__(self, type, value, traceback): ... + def __float__(self): ... + def __ge__(self, other): ... + def __getitem__(self, index): ... + def __gt__(self, other): ... + def __hash__(self): ... + def __int__(self): ... + def __iter__(self): ... + def __le__(self, other): ... + def __len__(self): ... + def __lt__(self, other): ... + def __ne__(self, other): ... + def __radd__(self, other): ... + def __rsub__(self, other): ... + def __setitem__(self, index, object): ... + def __sub__(self, other): ... + +@final +class buffer: + __hash__: ClassVar[None] # type: ignore[assignment] + def __init__(self, *args, **kwargs) -> None: ... + def __delitem__(self, other): ... + def __eq__(self, other): ... + def __ge__(self, other): ... + def __getitem__(self, index): ... + def __gt__(self, other): ... + def __le__(self, other): ... + def __len__(self): ... + def __lt__(self, other): ... + def __ne__(self, other): ... + def __setitem__(self, index, object): ... + +# These aliases are to work around pyright complaints. +# Pyright doesn't like it when a class object is defined as an alias +# of a global object with the same name. +_tmp_CType = CType +_tmp_buffer = buffer + +class FFI: + CData: TypeAlias = _CDataBase + CType: TypeAlias = _tmp_CType + buffer: TypeAlias = _tmp_buffer # noqa: Y042 + + class error(Exception): ... + NULL: ClassVar[CData] + RTLD_GLOBAL: ClassVar[int] + RTLD_LAZY: ClassVar[int] + RTLD_LOCAL: ClassVar[int] + RTLD_NOW: ClassVar[int] + if sys.platform != "win32": + RTLD_DEEPBIND: ClassVar[int] + RTLD_NODELETE: ClassVar[int] + RTLD_NOLOAD: ClassVar[int] + + errno: int + + def __init__( + self, + module_name: str = ..., + _version: int = ..., + _types: str = ..., + _globals: tuple[str | int, ...] = ..., + _struct_unions: tuple[tuple[str, ...], ...] = ..., + _enums: tuple[str, ...] = ..., + _typenames: tuple[str, ...] = ..., + _includes: tuple[FFI, ...] = ..., + ) -> None: ... + @overload + def addressof(self, __cdata: CData, *field_or_index: str | int) -> CData: ... + @overload + def addressof(self, __library: Lib, __name: str) -> CData: ... + def alignof(self, __cdecl: str | CType | CData) -> int: ... + @overload + def callback( + self, + cdecl: str | CType, + python_callable: None = ..., + error: Any = ..., + onerror: Callable[[Exception, Any, Any], None] | None = ..., + ) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... + @overload + def callback( + self, + cdecl: str | CType, + python_callable: Callable[..., _T], + error: Any = ..., + onerror: Callable[[Exception, Any, Any], None] | None = ..., + ) -> Callable[..., _T]: ... + def cast(self, cdecl: str | CType, value: CData) -> CData: ... + def def_extern( + self, name: str = ..., error: Any = ..., onerror: Callable[[Exception, Any, types.TracebackType], Any] = ... + ) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... + def dlclose(self, __lib: Lib) -> None: ... + if sys.platform == "win32": + def dlopen(self, __libpath: str | CData, __flags: int = ...) -> Lib: ... + else: + def dlopen(self, __libpath: str | CData | None = ..., __flags: int = ...) -> Lib: ... + + @overload + def from_buffer(self, cdecl: ReadableBuffer, require_writable: Literal[False] = ...) -> CData: ... + @overload + def from_buffer(self, cdecl: WriteableBuffer, require_writable: Literal[True]) -> CData: ... + @overload + def from_buffer(self, cdecl: str | CType, python_buffer: ReadableBuffer, require_writable: Literal[False] = ...) -> CData: ... + @overload + def from_buffer(self, cdecl: str | CType, python_buffer: WriteableBuffer, require_writable: Literal[True]) -> CData: ... + def from_handle(self, __x: CData) -> Any: ... + @overload + def gc(self, cdata: CData, destructor: Callable[[CData], Any], size: int = ...) -> CData: ... + @overload + def gc(self, cdata: CData, destructor: None, size: int = ...) -> None: ... + def getctype(self, cdecl: str | CType, replace_with: str = ...) -> str: ... + if sys.platform == "win32": + def getwinerror(self, code: int = ...) -> tuple[int, str]: ... + + def init_once(self, func: Callable[[], Any], tag: Hashable) -> Any: ... + def integer_const(self, name: str) -> int: ... + def list_types(self) -> tuple[list[str], list[str], list[str]]: ... + def memmove(self, dest: CData | WriteableBuffer, src: CData | ReadableBuffer, n: int) -> None: ... + def new(self, cdecl: str | CType, init: Any = ...) -> CData: ... + @overload + def new_allocator(self, alloc: None = ..., free: None = ..., should_clear_after_alloc: bool = ...) -> _Allocator: ... + @overload + def new_allocator( + self, alloc: Callable[[int], CData], free: None = ..., should_clear_after_alloc: bool = ... + ) -> _Allocator: ... + @overload + def new_allocator( + self, alloc: Callable[[int], CData], free: Callable[[CData], Any], should_clear_after_alloc: bool = ... + ) -> _Allocator: ... + def new_handle(self, __x: Any) -> CData: ... + def offsetof(self, __cdecl: str | CType, __field_or_index: str | int, *__fields_or_indexes: str | int) -> int: ... + def release(self, __cdata: CData) -> None: ... + def sizeof(self, __cdecl: str | CType | CData) -> int: ... + def string(self, cdata: CData, maxlen: int) -> bytes | str: ... + def typeof(self, cdecl: str | CData) -> CType: ... + def unpack(self, cdata: CData, length: int) -> bytes | str | list[Any]: ... + +def alignof(__cdecl: CType) -> int: ... +def callback( + __cdecl: CType, + __python_callable: Callable[..., _T], + __error: Any = ..., + __onerror: Callable[[Exception, Any, Any], None] | None = ..., +) -> Callable[..., _T]: ... +def cast(__cdecl: CType, __value: _CDataBase) -> _CDataBase: ... +def complete_struct_or_union( + __cdecl: CType, + __fields: list[tuple[str, CType, int, int]], + __ignored: Any, + __total_size: int, + __total_alignment: int, + __sflags: int, + __pack: int, +) -> None: ... +@overload +def from_buffer(__cdecl: CType, __python_buffer: ReadableBuffer, require_writable: Literal[False] = ...) -> _CDataBase: ... +@overload +def from_buffer(__cdecl: CType, __python_buffer: WriteableBuffer, require_writable: Literal[True]) -> _CDataBase: ... +def from_handle(__x: _CDataBase) -> Any: ... +@overload +def gcp(cdata: _CDataBase, destructor: Callable[[_CDataBase], Any], size: int = ...) -> _CDataBase: ... +@overload +def gcp(cdata: _CDataBase, destructor: None, size: int = ...) -> None: ... +def get_errno() -> int: ... +def getcname(__cdecl: CType, __replace_with: str) -> str: ... + +if sys.platform == "win32": + def getwinerror(code: int = ...) -> tuple[int, str]: ... + +if sys.platform == "win32": + def load_library(__libpath: str | _CDataBase, __flags: int = ...) -> CLibrary: ... + +else: + def load_library(__libpath: str | _CDataBase | None = ..., __flags: int = ...) -> CLibrary: ... + +def memmove(dest: _CDataBase | WriteableBuffer, src: _CDataBase | ReadableBuffer, n: int) -> None: ... +def new_array_type(__cdecl: CType, __length: int | None) -> CType: ... +def new_enum_type(__name: str, __enumerators: tuple[str, ...], __enumvalues: tuple[Any, ...], __basetype: CType) -> CType: ... +def new_function_type(__args: tuple[CType, ...], __result: CType, __ellipsis: int, __abi: int) -> CType: ... +def new_pointer_type(__cdecl: CType) -> CType: ... +def new_primitive_type(__name: str) -> CType: ... +def new_struct_type(__name: str) -> CType: ... +def new_union_type(__name: str) -> CType: ... +def new_void_type() -> CType: ... +def newp(__cdecl: CType, __init: Any = ...) -> _CDataBase: ... +def newp_handle(__cdecl: CType, __x: Any) -> _CDataBase: ... +def rawaddressof(__cdecl: CType, __cdata: _CDataBase, __offset: int) -> _CDataBase: ... +def release(__cdata: _CDataBase) -> None: ... +def set_errno(__errno: int) -> None: ... +def sizeof(__cdecl: CType | _CDataBase) -> int: ... +def string(cdata: _CDataBase, maxlen: int) -> bytes | str: ... +def typeof(__cdata: _CDataBase) -> CType: ... +def typeoffsetof(__cdecl: CType, __fieldname: str | int, __following: bool = ...) -> tuple[CType, int]: ... +def unpack(cdata: _CDataBase, length: int) -> bytes | str | list[Any]: ... diff --git a/stubs/cffi/cffi/__init__.pyi b/stubs/cffi/cffi/__init__.pyi new file mode 100644 index 000000000..851066f61 --- /dev/null +++ b/stubs/cffi/cffi/__init__.pyi @@ -0,0 +1,11 @@ +from .api import FFI as FFI +from .error import ( + CDefError as CDefError, + FFIError as FFIError, + VerificationError as VerificationError, + VerificationMissing as VerificationMissing, +) + +__version__: str +__version_info__: tuple[int, int, int] +__version_verifier_modules__: str diff --git a/stubs/cffi/cffi/api.pyi b/stubs/cffi/cffi/api.pyi new file mode 100644 index 000000000..751f7d1fd --- /dev/null +++ b/stubs/cffi/cffi/api.pyi @@ -0,0 +1,95 @@ +import distutils.core +import sys +import types +from _typeshed import ReadableBuffer, WriteableBuffer +from collections.abc import Callable, Hashable +from typing import Any, TypeVar, overload +from typing_extensions import Literal, TypeAlias + +import _cffi_backend + +_T = TypeVar("_T") + +basestring: TypeAlias = str # noqa: Y042 + +class FFI: + CData: TypeAlias = _cffi_backend._CDataBase + CType: TypeAlias = _cffi_backend.CType + buffer: TypeAlias = _cffi_backend.buffer # noqa: Y042 + + BVoidP: CType + BCharA: CType + NULL: CType + errno: int + + def __init__(self, backend: types.ModuleType | None = ...) -> None: ... + def cdef(self, csource: str, override: bool = ..., packed: bool = ..., pack: int | None = ...) -> None: ... + def embedding_api(self, csource: str, packed: bool = ..., pack: bool | int | None = ...) -> None: ... + def dlopen(self, name: str, flags: int = ...) -> _cffi_backend.Lib: ... + def dlclose(self, lib: _cffi_backend.Lib) -> None: ... + def typeof(self, cdecl: str | CData | types.BuiltinFunctionType | types.FunctionType) -> CType: ... + def sizeof(self, cdecl: str | CData) -> int: ... + def alignof(self, cdecl: str | CData) -> int: ... + def offsetof(self, cdecl: str | CData, *fields_or_indexes: str | int) -> int: ... + def new(self, cdecl: str | CType, init: Any | None = ...) -> CData: ... + def new_allocator( + self, + alloc: Callable[[int], CData] | None = ..., + free: Callable[[CData], Any] | None = ..., + should_clear_after_alloc: bool = ..., + ) -> _cffi_backend._Allocator: ... + def cast(self, cdecl: str | CType, source: CData) -> CData: ... + def string(self, cdata: CData, maxlen: int = ...) -> bytes | str: ... + def unpack(self, cdata: CData, length: int) -> bytes | str | list[Any]: ... + @overload + def from_buffer(self, cdecl: ReadableBuffer, require_writable: Literal[False] = ...) -> CData: ... + @overload + def from_buffer(self, cdecl: WriteableBuffer, require_writable: Literal[True]) -> CData: ... + @overload + def from_buffer(self, cdecl: str, python_buffer: ReadableBuffer, require_writable: Literal[False] = ...) -> CData: ... + @overload + def from_buffer(self, cdecl: str, python_buffer: WriteableBuffer, require_writable: Literal[True]) -> CData: ... + def memmove(self, dest: CData | WriteableBuffer, src: CData | ReadableBuffer, n: int) -> None: ... + @overload + def callback( + self, + cdecl: str | CType, + python_callable: None = ..., + error: Any = ..., + onerror: Callable[[Exception, Any, Any], None] | None = ..., + ) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... + @overload + def callback( + self, + cdecl: str | CType, + python_callable: Callable[..., _T], + error: Any = ..., + onerror: Callable[[Exception, Any, Any], None] | None = ..., + ) -> Callable[..., _T]: ... + def getctype(self, cdecl: str | CType, replace_with: str = ...) -> str: ... + @overload + def gc(self, cdata: CData, destructor: Callable[[CData], Any], size: int = ...) -> CData: ... + @overload + def gc(self, cdata: CData, destructor: None, size: int = ...) -> None: ... + def verify(self, source: str = ..., tmpdir: str | None = ..., **kwargs: Any) -> _cffi_backend.Lib: ... + if sys.platform == "win32": + def getwinerror(self, code: int = ...) -> tuple[int, str] | None: ... + + def addressof(self, cdata: CData, *fields_or_indexes: str | int) -> CData: ... + def include(self, ffi_to_include: FFI) -> None: ... + def new_handle(self, x: Any) -> CData: ... + def from_handle(self, x: CData) -> Any: ... + def release(self, x: CData) -> None: ... + def set_unicode(self, enabled_flag: bool) -> None: ... + def set_source(self, module_name: str, source: str, source_extension: str = ..., **kwds: Any) -> None: ... + def set_source_pkgconfig( + self, module_name: str, pkgconfig_libs: list[str], source: str, source_extension: str = ..., **kwds: Any + ) -> None: ... + def distutils_extension(self, tmpdir: str = ..., verbose: bool = ...) -> distutils.core.Extension: ... + def emit_c_code(self, filename: str) -> None: ... + def emit_python_code(self, filename: str) -> None: ... + def compile(self, tmpdir: str = ..., verbose: int = ..., target: str | None = ..., debug: bool | None = ...) -> str: ... + def init_once(self, func: Callable[[], Any], tag: Hashable) -> Any: ... + def embedding_init_code(self, pysource: str) -> None: ... + def def_extern(self, *args: Any, **kwds: Any) -> None: ... + def list_types(self) -> tuple[list[str], list[str], list[str]]: ... diff --git a/stubs/cffi/cffi/backend_ctypes.pyi b/stubs/cffi/cffi/backend_ctypes.pyi new file mode 100644 index 000000000..d202d87de --- /dev/null +++ b/stubs/cffi/cffi/backend_ctypes.pyi @@ -0,0 +1,79 @@ +from _typeshed import Incomplete + +unicode = str +long = int +xrange = range +bytechr: Incomplete + +class CTypesType(type): ... + +class CTypesData: + __metaclass__: Incomplete + __name__: str + def __init__(self, *args) -> None: ... + def __iter__(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + def __lt__(self, other): ... + def __le__(self, other): ... + def __gt__(self, other): ... + def __ge__(self, other): ... + def __hash__(self): ... + def __repr__(self, c_name: str | None = ...): ... + +class CTypesGenericPrimitive(CTypesData): + def __hash__(self): ... + +class CTypesGenericArray(CTypesData): + def __iter__(self): ... + +class CTypesGenericPtr(CTypesData): + kind: str + def __nonzero__(self): ... + def __bool__(self) -> bool: ... + +class CTypesBaseStructOrUnion(CTypesData): ... + +class CTypesBackend: + PRIMITIVE_TYPES: Incomplete + RTLD_LAZY: int + RTLD_NOW: int + RTLD_GLOBAL: Incomplete + RTLD_LOCAL: Incomplete + def __init__(self) -> None: ... + ffi: Incomplete + def set_ffi(self, ffi) -> None: ... + def load_library(self, path, flags: int = ...): ... + def new_void_type(self): ... + def new_primitive_type(self, name): ... + def new_pointer_type(self, BItem): ... + def new_array_type(self, CTypesPtr, length): ... + def new_struct_type(self, name): ... + def new_union_type(self, name): ... + def complete_struct_or_union( + self, CTypesStructOrUnion, fields, tp, totalsize: int = ..., totalalignment: int = ..., sflags: int = ..., pack: int = ... + ): ... + def new_function_type(self, BArgs, BResult, has_varargs): ... + def new_enum_type(self, name, enumerators, enumvalues, CTypesInt): ... + def get_errno(self): ... + def set_errno(self, value) -> None: ... + def string(self, b, maxlen: int = ...): ... + def buffer(self, bptr, size: int = ...) -> None: ... + def sizeof(self, cdata_or_BType): ... + def alignof(self, BType): ... + def newp(self, BType, source): ... + def cast(self, BType, source): ... + def callback(self, BType, source, error, onerror): ... + def gcp(self, cdata, destructor, size: int = ...): ... + typeof: Incomplete + def getcname(self, BType, replace_with): ... + def typeoffsetof(self, BType, fieldname, num: int = ...): ... + def rawaddressof(self, BTypePtr, cdata, offset: Incomplete | None = ...): ... + +class CTypesLibrary: + backend: Incomplete + cdll: Incomplete + def __init__(self, backend, cdll) -> None: ... + def load_function(self, BType, name): ... + def read_variable(self, BType, name): ... + def write_variable(self, BType, name, value) -> None: ... diff --git a/stubs/cffi/cffi/cffi_opcode.pyi b/stubs/cffi/cffi/cffi_opcode.pyi new file mode 100644 index 000000000..364a0808d --- /dev/null +++ b/stubs/cffi/cffi/cffi_opcode.pyi @@ -0,0 +1,92 @@ +from _typeshed import Incomplete + +class CffiOp: + op: Incomplete + arg: Incomplete + def __init__(self, op, arg) -> None: ... + def as_c_expr(self): ... + def as_python_bytes(self): ... + +def format_four_bytes(num): ... + +OP_PRIMITIVE: int +OP_POINTER: int +OP_ARRAY: int +OP_OPEN_ARRAY: int +OP_STRUCT_UNION: int +OP_ENUM: int +OP_FUNCTION: int +OP_FUNCTION_END: int +OP_NOOP: int +OP_BITFIELD: int +OP_TYPENAME: int +OP_CPYTHON_BLTN_V: int +OP_CPYTHON_BLTN_N: int +OP_CPYTHON_BLTN_O: int +OP_CONSTANT: int +OP_CONSTANT_INT: int +OP_GLOBAL_VAR: int +OP_DLOPEN_FUNC: int +OP_DLOPEN_CONST: int +OP_GLOBAL_VAR_F: int +OP_EXTERN_PYTHON: int +PRIM_VOID: int +PRIM_BOOL: int +PRIM_CHAR: int +PRIM_SCHAR: int +PRIM_UCHAR: int +PRIM_SHORT: int +PRIM_USHORT: int +PRIM_INT: int +PRIM_UINT: int +PRIM_LONG: int +PRIM_ULONG: int +PRIM_LONGLONG: int +PRIM_ULONGLONG: int +PRIM_FLOAT: int +PRIM_DOUBLE: int +PRIM_LONGDOUBLE: int +PRIM_WCHAR: int +PRIM_INT8: int +PRIM_UINT8: int +PRIM_INT16: int +PRIM_UINT16: int +PRIM_INT32: int +PRIM_UINT32: int +PRIM_INT64: int +PRIM_UINT64: int +PRIM_INTPTR: int +PRIM_UINTPTR: int +PRIM_PTRDIFF: int +PRIM_SIZE: int +PRIM_SSIZE: int +PRIM_INT_LEAST8: int +PRIM_UINT_LEAST8: int +PRIM_INT_LEAST16: int +PRIM_UINT_LEAST16: int +PRIM_INT_LEAST32: int +PRIM_UINT_LEAST32: int +PRIM_INT_LEAST64: int +PRIM_UINT_LEAST64: int +PRIM_INT_FAST8: int +PRIM_UINT_FAST8: int +PRIM_INT_FAST16: int +PRIM_UINT_FAST16: int +PRIM_INT_FAST32: int +PRIM_UINT_FAST32: int +PRIM_INT_FAST64: int +PRIM_UINT_FAST64: int +PRIM_INTMAX: int +PRIM_UINTMAX: int +PRIM_FLOATCOMPLEX: int +PRIM_DOUBLECOMPLEX: int +PRIM_CHAR16: int +PRIM_CHAR32: int +PRIMITIVE_TO_INDEX: Incomplete +F_UNION: int +F_CHECK_FIELDS: int +F_PACKED: int +F_EXTERNAL: int +F_OPAQUE: int +G_FLAGS: Incomplete +CLASS_NAME: Incomplete diff --git a/stubs/cffi/cffi/commontypes.pyi b/stubs/cffi/cffi/commontypes.pyi new file mode 100644 index 000000000..fe9e35ee5 --- /dev/null +++ b/stubs/cffi/cffi/commontypes.pyi @@ -0,0 +1,6 @@ +from _typeshed import Incomplete + +COMMON_TYPES: Incomplete + +def resolve_common_type(parser, commontype): ... +def win_common_types(): ... diff --git a/stubs/cffi/cffi/cparser.pyi b/stubs/cffi/cffi/cparser.pyi new file mode 100644 index 000000000..8fcab85b1 --- /dev/null +++ b/stubs/cffi/cffi/cparser.pyi @@ -0,0 +1,14 @@ +from _typeshed import Incomplete + +lock: Incomplete +CDEF_SOURCE_STRING: str + +class Parser: + def __init__(self) -> None: ... + def convert_pycparser_error(self, e, csource) -> None: ... + def parse( + self, csource, override: bool = ..., packed: bool = ..., pack: Incomplete | None = ..., dllexport: bool = ... + ) -> None: ... + def parse_type(self, cdecl): ... + def parse_type_and_quals(self, cdecl): ... + def include(self, other) -> None: ... diff --git a/stubs/cffi/cffi/error.pyi b/stubs/cffi/cffi/error.pyi new file mode 100644 index 000000000..a71f17e5d --- /dev/null +++ b/stubs/cffi/cffi/error.pyi @@ -0,0 +1,14 @@ +class FFIError(Exception): + __module__: str + +class CDefError(Exception): + __module__: str + +class VerificationError(Exception): + __module__: str + +class VerificationMissing(Exception): + __module__: str + +class PkgConfigError(Exception): + __module__: str diff --git a/stubs/cffi/cffi/ffiplatform.pyi b/stubs/cffi/cffi/ffiplatform.pyi new file mode 100644 index 000000000..d96b7559b --- /dev/null +++ b/stubs/cffi/cffi/ffiplatform.pyi @@ -0,0 +1,11 @@ +from _typeshed import Incomplete + +LIST_OF_FILE_NAMES: Incomplete + +def get_extension(srcfilename, modname, sources=..., **kwds): ... +def compile(tmpdir, ext, compiler_verbose: int = ..., debug: Incomplete | None = ...): ... +def maybe_relative_path(path): ... + +int_or_long = int + +def flatten(x): ... diff --git a/stubs/cffi/cffi/lock.pyi b/stubs/cffi/cffi/lock.pyi new file mode 100644 index 000000000..fc8393af7 --- /dev/null +++ b/stubs/cffi/cffi/lock.pyi @@ -0,0 +1 @@ +from _thread import allocate_lock as allocate_lock diff --git a/stubs/cffi/cffi/model.pyi b/stubs/cffi/cffi/model.pyi new file mode 100644 index 000000000..8e1915892 --- /dev/null +++ b/stubs/cffi/cffi/model.pyi @@ -0,0 +1,162 @@ +from _typeshed import Incomplete +from collections.abc import Generator + +from .error import CDefError as CDefError, VerificationError as VerificationError, VerificationMissing as VerificationMissing +from .lock import allocate_lock as allocate_lock + +Q_CONST: int +Q_RESTRICT: int +Q_VOLATILE: int + +def qualify(quals, replace_with): ... + +class BaseTypeByIdentity: + is_array_type: bool + is_raw_function: bool + def get_c_name(self, replace_with: str = ..., context: str = ..., quals: int = ...): ... + def has_c_name(self): ... + def is_integer_type(self): ... + def get_cached_btype(self, ffi, finishlist, can_delay: bool = ...): ... + +class BaseType(BaseTypeByIdentity): + def __eq__(self, other): ... + def __ne__(self, other): ... + def __hash__(self): ... + +class VoidType(BaseType): + c_name_with_marker: str + def __init__(self) -> None: ... + def build_backend_type(self, ffi, finishlist): ... + +void_type: Incomplete + +class BasePrimitiveType(BaseType): + def is_complex_type(self): ... + +class PrimitiveType(BasePrimitiveType): + ALL_PRIMITIVE_TYPES: Incomplete + name: Incomplete + c_name_with_marker: Incomplete + def __init__(self, name) -> None: ... + def is_char_type(self): ... + def is_integer_type(self): ... + def is_float_type(self): ... + def is_complex_type(self): ... + def build_backend_type(self, ffi, finishlist): ... + +class UnknownIntegerType(BasePrimitiveType): + name: Incomplete + c_name_with_marker: Incomplete + def __init__(self, name) -> None: ... + def is_integer_type(self): ... + def build_backend_type(self, ffi, finishlist) -> None: ... + +class UnknownFloatType(BasePrimitiveType): + name: Incomplete + c_name_with_marker: Incomplete + def __init__(self, name) -> None: ... + def build_backend_type(self, ffi, finishlist) -> None: ... + +class BaseFunctionType(BaseType): + args: Incomplete + result: Incomplete + ellipsis: Incomplete + abi: Incomplete + c_name_with_marker: Incomplete + def __init__(self, args, result, ellipsis, abi: Incomplete | None = ...) -> None: ... + +class RawFunctionType(BaseFunctionType): + is_raw_function: bool + def build_backend_type(self, ffi, finishlist) -> None: ... + def as_function_pointer(self): ... + +class FunctionPtrType(BaseFunctionType): + def build_backend_type(self, ffi, finishlist): ... + def as_raw_function(self): ... + +class PointerType(BaseType): + totype: Incomplete + quals: Incomplete + c_name_with_marker: Incomplete + def __init__(self, totype, quals: int = ...) -> None: ... + def build_backend_type(self, ffi, finishlist): ... + +voidp_type: Incomplete + +def ConstPointerType(totype): ... + +const_voidp_type: Incomplete + +class NamedPointerType(PointerType): + name: Incomplete + c_name_with_marker: Incomplete + def __init__(self, totype, name, quals: int = ...) -> None: ... + +class ArrayType(BaseType): + is_array_type: bool + item: Incomplete + length: Incomplete + c_name_with_marker: Incomplete + def __init__(self, item, length) -> None: ... + def length_is_unknown(self): ... + def resolve_length(self, newlength): ... + def build_backend_type(self, ffi, finishlist): ... + +char_array_type: Incomplete + +class StructOrUnionOrEnum(BaseTypeByIdentity): + forcename: Incomplete + c_name_with_marker: Incomplete + def build_c_name_with_marker(self) -> None: ... + def force_the_name(self, forcename) -> None: ... + def get_official_name(self): ... + +class StructOrUnion(StructOrUnionOrEnum): + fixedlayout: Incomplete + completed: int + partial: bool + packed: int + name: Incomplete + fldnames: Incomplete + fldtypes: Incomplete + fldbitsize: Incomplete + fldquals: Incomplete + def __init__(self, name, fldnames, fldtypes, fldbitsize, fldquals: Incomplete | None = ...) -> None: ... + def anonymous_struct_fields(self) -> Generator[Incomplete, None, None]: ... + def enumfields(self, expand_anonymous_struct_union: bool = ...) -> Generator[Incomplete, None, None]: ... + def force_flatten(self) -> None: ... + def get_cached_btype(self, ffi, finishlist, can_delay: bool = ...): ... + def finish_backend_type(self, ffi, finishlist) -> None: ... + def check_not_partial(self) -> None: ... + def build_backend_type(self, ffi, finishlist): ... + +class StructType(StructOrUnion): + kind: str + +class UnionType(StructOrUnion): + kind: str + +class EnumType(StructOrUnionOrEnum): + kind: str + partial: bool + partial_resolved: bool + name: Incomplete + enumerators: Incomplete + enumvalues: Incomplete + baseinttype: Incomplete + def __init__(self, name, enumerators, enumvalues, baseinttype: Incomplete | None = ...) -> None: ... + forcename: Incomplete + def force_the_name(self, forcename) -> None: ... + def check_not_partial(self) -> None: ... + def build_backend_type(self, ffi, finishlist): ... + def build_baseinttype(self, ffi, finishlist): ... + +def unknown_type(name, structname: Incomplete | None = ...): ... +def unknown_ptr_type(name, structname: Incomplete | None = ...): ... + +global_lock: Incomplete + +def get_typecache(backend): ... +def global_cache(srctype, ffi, funcname, *args, **kwds): ... +def pointer_cache(ffi, BType): ... +def attach_exception_info(e, name) -> None: ... diff --git a/stubs/cffi/cffi/pkgconfig.pyi b/stubs/cffi/cffi/pkgconfig.pyi new file mode 100644 index 000000000..bb53098f0 --- /dev/null +++ b/stubs/cffi/cffi/pkgconfig.pyi @@ -0,0 +1,3 @@ +def merge_flags(cfg1, cfg2): ... +def call(libname, flag, encoding=...): ... +def flags_from_pkgconfig(libs): ... diff --git a/stubs/cffi/cffi/recompiler.pyi b/stubs/cffi/cffi/recompiler.pyi new file mode 100644 index 000000000..ee17f6b16 --- /dev/null +++ b/stubs/cffi/cffi/recompiler.pyi @@ -0,0 +1,94 @@ +import io +from _typeshed import Incomplete +from typing_extensions import TypeAlias + +from .cffi_opcode import * + +VERSION_BASE: int +VERSION_EMBEDDED: int +VERSION_CHAR16CHAR32: int +USE_LIMITED_API: Incomplete + +class GlobalExpr: + name: Incomplete + address: Incomplete + type_op: Incomplete + size: Incomplete + check_value: Incomplete + def __init__(self, name, address, type_op, size: int = ..., check_value: int = ...) -> None: ... + def as_c_expr(self): ... + def as_python_expr(self): ... + +class FieldExpr: + name: Incomplete + field_offset: Incomplete + field_size: Incomplete + fbitsize: Incomplete + field_type_op: Incomplete + def __init__(self, name, field_offset, field_size, fbitsize, field_type_op) -> None: ... + def as_c_expr(self): ... + def as_python_expr(self) -> None: ... + def as_field_python_expr(self): ... + +class StructUnionExpr: + name: Incomplete + type_index: Incomplete + flags: Incomplete + size: Incomplete + alignment: Incomplete + comment: Incomplete + first_field_index: Incomplete + c_fields: Incomplete + def __init__(self, name, type_index, flags, size, alignment, comment, first_field_index, c_fields) -> None: ... + def as_c_expr(self): ... + def as_python_expr(self): ... + +class EnumExpr: + name: Incomplete + type_index: Incomplete + size: Incomplete + signed: Incomplete + allenums: Incomplete + def __init__(self, name, type_index, size, signed, allenums) -> None: ... + def as_c_expr(self): ... + def as_python_expr(self): ... + +class TypenameExpr: + name: Incomplete + type_index: Incomplete + def __init__(self, name, type_index) -> None: ... + def as_c_expr(self): ... + def as_python_expr(self): ... + +class Recompiler: + ffi: Incomplete + module_name: Incomplete + target_is_python: Incomplete + def __init__(self, ffi, module_name, target_is_python: bool = ...) -> None: ... + def needs_version(self, ver) -> None: ... + cffi_types: Incomplete + def collect_type_table(self): ... + ALL_STEPS: Incomplete + def collect_step_tables(self): ... + def write_source_to_f(self, f, preamble) -> None: ... + def write_c_source_to_f(self, f, preamble) -> None: ... + def write_py_source_to_f(self, f) -> None: ... + +NativeIO: TypeAlias = io.StringIO + +def make_c_source(ffi, module_name, preamble, target_c_file, verbose: bool = ...): ... +def make_py_source(ffi, module_name, target_py_file, verbose: bool = ...): ... +def recompile( + ffi, + module_name, + preamble, + tmpdir: str = ..., + call_c_compiler: bool = ..., + c_file: Incomplete | None = ..., + source_extension: str = ..., + extradir: Incomplete | None = ..., + compiler_verbose: int = ..., + target: Incomplete | None = ..., + debug: Incomplete | None = ..., + **kwds, +): ... diff --git a/stubs/cffi/cffi/setuptools_ext.pyi b/stubs/cffi/cffi/setuptools_ext.pyi new file mode 100644 index 000000000..beb588589 --- /dev/null +++ b/stubs/cffi/cffi/setuptools_ext.pyi @@ -0,0 +1,6 @@ +basestring = str + +def error(msg) -> None: ... +def execfile(filename, glob) -> None: ... +def add_cffi_module(dist, mod_spec) -> None: ... +def cffi_modules(dist, attr, value) -> None: ... diff --git a/stubs/cffi/cffi/vengine_cpy.pyi b/stubs/cffi/cffi/vengine_cpy.pyi new file mode 100644 index 000000000..dea9f16f8 --- /dev/null +++ b/stubs/cffi/cffi/vengine_cpy.pyi @@ -0,0 +1,13 @@ +from _typeshed import Incomplete + +class VCPythonEngine: + verifier: Incomplete + ffi: Incomplete + def __init__(self, verifier) -> None: ... + def patch_extension_kwds(self, kwds) -> None: ... + def find_module(self, module_name, path, so_suffixes): ... + def collect_types(self) -> None: ... + def write_source_to_f(self) -> None: ... + def load_library(self, flags: Incomplete | None = ...): ... + +cffimod_header: str diff --git a/stubs/cffi/cffi/vengine_gen.pyi b/stubs/cffi/cffi/vengine_gen.pyi new file mode 100644 index 000000000..d4477094c --- /dev/null +++ b/stubs/cffi/cffi/vengine_gen.pyi @@ -0,0 +1,14 @@ +from _typeshed import Incomplete + +class VGenericEngine: + verifier: Incomplete + ffi: Incomplete + export_symbols: Incomplete + def __init__(self, verifier) -> None: ... + def patch_extension_kwds(self, kwds) -> None: ... + def find_module(self, module_name, path, so_suffixes): ... + def collect_types(self) -> None: ... + def write_source_to_f(self) -> None: ... + def load_library(self, flags: int = ...): ... + +cffimod_header: str diff --git a/stubs/cffi/cffi/verifier.pyi b/stubs/cffi/cffi/verifier.pyi new file mode 100644 index 000000000..3b9e558ca --- /dev/null +++ b/stubs/cffi/cffi/verifier.pyi @@ -0,0 +1,39 @@ +import io +from _typeshed import Incomplete +from typing_extensions import TypeAlias + +NativeIO: TypeAlias = io.StringIO + +class Verifier: + ffi: Incomplete + preamble: Incomplete + flags: Incomplete + kwds: Incomplete + tmpdir: Incomplete + sourcefilename: Incomplete + modulefilename: Incomplete + ext_package: Incomplete + def __init__( + self, + ffi, + preamble, + tmpdir: Incomplete | None = ..., + modulename: Incomplete | None = ..., + ext_package: Incomplete | None = ..., + tag: str = ..., + force_generic_engine: bool = ..., + source_extension: str = ..., + flags: Incomplete | None = ..., + relative_to: Incomplete | None = ..., + **kwds, + ) -> None: ... + def write_source(self, file: Incomplete | None = ...) -> None: ... + def compile_module(self) -> None: ... + def load_library(self): ... + def get_module_name(self): ... + def get_extension(self): ... + def generates_python_module(self): ... + def make_relative_to(self, kwds, relative_to): ... + +def set_tmpdir(dirname) -> None: ... +def cleanup_tmpdir(tmpdir: Incomplete | None = ..., keep_so: bool = ...) -> None: ...