Skip to content

Commit 9b2a355

Browse files
authored
[_cffi_backend] Improve CField, CType, _CDataBase, buffer
1 parent 50ec910 commit 9b2a355

File tree

1 file changed

+54
-47
lines changed

1 file changed

+54
-47
lines changed

stubs/cffi/_cffi_backend.pyi

Lines changed: 54 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import sys
22
import types
33
from _typeshed import Incomplete, ReadableBuffer, WriteableBuffer
44
from collections.abc import Callable, Hashable
5-
from typing import Any, ClassVar, Literal, Protocol, SupportsIndex, TypeVar, final, overload, type_check_only
5+
from typing import Any, ClassVar, Literal, Optional, Protocol, Self, SupportsIndex, TypeVar, final, overload, type_check_only
66
from typing_extensions import Self, TypeAlias, disjoint_base
77

88
_T = TypeVar("_T")
@@ -27,11 +27,11 @@ if sys.platform != "win32":
2727

2828
@final
2929
class CField:
30-
bitshift: Incomplete
31-
bitsize: Incomplete
32-
flags: Incomplete
33-
offset: Incomplete
34-
type: Incomplete
30+
bitshift: int
31+
bitsize: int
32+
flags: int
33+
offset: int
34+
type: 'CType'
3535

3636
@final
3737
class CLibrary:
@@ -42,18 +42,21 @@ class CLibrary:
4242

4343
@final
4444
class CType:
45-
abi: Incomplete
46-
args: Incomplete
47-
cname: Incomplete
48-
elements: Incomplete
49-
ellipsis: Incomplete
50-
fields: Incomplete
51-
item: Incomplete
52-
kind: Incomplete
53-
length: Incomplete
54-
relements: Incomplete
55-
result: Incomplete
56-
def __dir__(self): ...
45+
cname: str
46+
kind: Literal['enum', 'primitive', 'pointer', 'array', 'void', 'struct', 'union', 'function']
47+
48+
abi: int
49+
args: tuple['CType', ...]
50+
ellipsis: bool
51+
result: 'CType'
52+
53+
item: 'CType'
54+
length: Optional[int]
55+
56+
fields: Optional[list[tuple[str, CField]]]
57+
58+
relements: dict[str, int]
59+
elements: dict[int, str]
5760

5861
@final
5962
class Lib:
@@ -62,48 +65,52 @@ class Lib:
6265
@final
6366
class _CDataBase:
6467
__name__: ClassVar[str]
65-
def __add__(self, other, /): ...
66-
def __bool__(self) -> bool: ...
67-
def __call__(self, *args, **kwargs): ...
68-
def __complex__(self) -> complex: ...
69-
def __delitem__(self, other, /) -> None: ...
7068
def __dir__(self): ...
71-
def __enter__(self): ...
72-
def __eq__(self, other, /): ...
69+
70+
def __enter__(self) -> Self: ...
7371
def __exit__(
7472
self, type: type[BaseException] | None, value: BaseException | None, traceback: types.TracebackType | None, /
7573
): ...
74+
75+
def __add__(self, other, /): ...
76+
def __sub__(self, other, /): ...
77+
def __radd__(self, other, /): ...
78+
def __rsub__(self, other, /): ...
79+
80+
def __call__(self, *args): ...
81+
82+
def __hash__(self) -> int: ...
83+
def __bool__(self) -> bool: ...
84+
def __int__(self) -> int: ...
7685
def __float__(self) -> float: ...
86+
def __complex__(self) -> complex: ...
87+
88+
def __eq__(self, other, /): ...
89+
def __ne__(self, other, /): ...
7790
def __ge__(self, other, /): ...
78-
def __getitem__(self, index: SupportsIndex | slice, /): ...
7991
def __gt__(self, other, /): ...
80-
def __hash__(self) -> int: ...
81-
def __int__(self) -> int: ...
82-
def __iter__(self): ...
8392
def __le__(self, other, /): ...
84-
def __len__(self) -> int: ...
8593
def __lt__(self, other, /): ...
86-
def __ne__(self, other, /): ...
87-
def __radd__(self, other, /): ...
88-
def __rsub__(self, other, /): ...
94+
95+
def __iter__(self): ...
96+
def __len__(self) -> int: ...
97+
def __getitem__(self, index: SupportsIndex | slice, /): ...
8998
def __setitem__(self, index: SupportsIndex | slice, object, /) -> None: ...
90-
def __sub__(self, other, /): ...
9199

92100
@final
93101
class buffer:
94-
__hash__: ClassVar[None] # type: ignore[assignment]
95-
def __new__(cls, *args, **kwargs) -> Self: ...
96-
def __buffer__(self, flags: int, /) -> memoryview: ...
97-
def __delitem__(self, other, /) -> None: ...
98-
def __eq__(self, other, /): ...
99-
def __ge__(self, other, /): ...
100-
def __getitem__(self, index, /): ...
101-
def __gt__(self, other, /): ...
102-
def __le__(self, other, /): ...
103-
def __len__(self) -> int: ...
104-
def __lt__(self, other, /): ...
105-
def __ne__(self, other, /): ...
106-
def __setitem__(self, index, object, /) -> None: ...
102+
__hash__: ClassVar[None] # type: ignore[assignment]
103+
def __new__(cls, cdata: _CDataBase, size: int = -1) -> Self: ...
104+
def __buffer__(self, flags: int, /) -> memoryview: ...
105+
def __eq__(self, other: ReadableBuffer, /) -> bool: ...
106+
def __ne__(self, other: ReadableBuffer, /) -> bool: ...
107+
def __ge__(self, other: ReadableBuffer, /) -> bool: ...
108+
def __gt__(self, other: ReadableBuffer, /) -> bool: ...
109+
def __le__(self, other: ReadableBuffer, /) -> bool: ...
110+
def __lt__(self, other: ReadableBuffer, /) -> bool: ...
111+
def __len__(self) -> int: ...
112+
def __getitem__(self, index: SupportsIndex | slice, /) -> bytes: ...
113+
def __setitem__(self, index: SupportsIndex | slice, value: bytes, /) -> None: ...
107114

108115
# These aliases are to work around pyright complaints.
109116
# Pyright doesn't like it when a class object is defined as an alias

0 commit comments

Comments
 (0)