Skip to content

Commit da6c754

Browse files
committed
separate _CField classes, one for 3.14+ and one for < 3.14
1 parent f24fe70 commit da6c754

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

stdlib/_ctypes.pyi

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,12 @@ class CFuncPtr(_PointerLike, _CData, metaclass=_PyCFuncPtrType):
195195
_GetT = TypeVar("_GetT")
196196
_SetT = TypeVar("_SetT")
197197

198-
@final
199-
class _CField(Generic[_CT, _GetT, _SetT]):
200-
offset: int
201-
size: int
202-
if sys.version_info >= (3, 14):
198+
if sys.version_info >= (3, 14):
199+
@final
200+
@type_check_only
201+
class _CField(Generic[_CT, _GetT, _SetT]):
202+
offset: int
203+
size: int
203204
name: str
204205
type: type[_CT]
205206
byte_offset: int
@@ -208,18 +209,30 @@ class _CField(Generic[_CT, _GetT, _SetT]):
208209
bit_offset: int
209210
bit_size: int
210211
is_anonymous: bool
211-
if sys.version_info >= (3, 10):
212212
@overload
213213
def __get__(self, instance: None, owner: type[Any] | None = None, /) -> Self: ...
214214
@overload
215215
def __get__(self, instance: Any, owner: type[Any] | None = None, /) -> _GetT: ...
216-
else:
217-
@overload
218-
def __get__(self, instance: None, owner: type[Any] | None, /) -> Self: ...
219-
@overload
220-
def __get__(self, instance: Any, owner: type[Any] | None, /) -> _GetT: ...
221216

222-
def __set__(self, instance: Any, value: _SetT, /) -> None: ...
217+
def __set__(self, instance: Any, value: _SetT, /) -> None: ...
218+
else:
219+
@final
220+
@type_check_only
221+
class _CField(Generic[_CT, _GetT, _SetT]):
222+
offset: int
223+
size: int
224+
if sys.version_info >= (3, 10):
225+
@overload
226+
def __get__(self, instance: None, owner: type[Any] | None = None, /) -> Self: ...
227+
@overload
228+
def __get__(self, instance: Any, owner: type[Any] | None = None, /) -> _GetT: ...
229+
else:
230+
@overload
231+
def __get__(self, instance: None, owner: type[Any] | None, /) -> Self: ...
232+
@overload
233+
def __get__(self, instance: Any, owner: type[Any] | None, /) -> _GetT: ...
234+
235+
def __set__(self, instance: Any, value: _SetT, /) -> None: ...
223236

224237
# This class is not exposed. It calls itself _ctypes.UnionType.
225238
@type_check_only

0 commit comments

Comments
 (0)