From 559b529c569fd62ec41b5f8fe90a57416a6ea806 Mon Sep 17 00:00:00 2001 From: guoci Date: Wed, 19 Nov 2025 11:13:42 -0500 Subject: [PATCH 01/11] update `ctypes.CField` --- stdlib/_ctypes.pyi | 10 ++++++++-- stdlib/ctypes/__init__.pyi | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/stdlib/_ctypes.pyi b/stdlib/_ctypes.pyi index c87cf5e326ca..3f35c7d94700 100644 --- a/stdlib/_ctypes.pyi +++ b/stdlib/_ctypes.pyi @@ -195,12 +195,18 @@ class CFuncPtr(_PointerLike, _CData, metaclass=_PyCFuncPtrType): _GetT = TypeVar("_GetT") _SetT = TypeVar("_SetT") -# This class is not exposed. It calls itself _ctypes.CField. @final -@type_check_only class _CField(Generic[_CT, _GetT, _SetT]): + name: str + type: type[_CT] offset: int + byte_offset: int + byte_size: int size: int + is_bitfield: bool + bit_offset: int + bit_size: int + is_anonymous: bool if sys.version_info >= (3, 10): @overload def __get__(self, instance: None, owner: type[Any] | None = None, /) -> Self: ... diff --git a/stdlib/ctypes/__init__.pyi b/stdlib/ctypes/__init__.pyi index 19bd261c67e0..6d82b90bdf4a 100644 --- a/stdlib/ctypes/__init__.pyi +++ b/stdlib/ctypes/__init__.pyi @@ -10,7 +10,7 @@ from _ctypes import ( _CArgObject as _CArgObject, _CData as _CData, _CDataType as _CDataType, - _CField as _CField, + _CField as CField, _CTypeBaseType, _Pointer as _Pointer, _PointerLike as _PointerLike, From d93892f73088f7736393c7b26c358f73ff7b9aef Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 19 Nov 2025 16:18:00 +0000 Subject: [PATCH 02/11] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/ctypes/__init__.pyi | 1 - 1 file changed, 1 deletion(-) diff --git a/stdlib/ctypes/__init__.pyi b/stdlib/ctypes/__init__.pyi index 6d82b90bdf4a..c64cee2791ca 100644 --- a/stdlib/ctypes/__init__.pyi +++ b/stdlib/ctypes/__init__.pyi @@ -10,7 +10,6 @@ from _ctypes import ( _CArgObject as _CArgObject, _CData as _CData, _CDataType as _CDataType, - _CField as CField, _CTypeBaseType, _Pointer as _Pointer, _PointerLike as _PointerLike, From 06041342194524928a6eebc72633d35a4ba27fbe Mon Sep 17 00:00:00 2001 From: guoci Date: Wed, 19 Nov 2025 11:23:22 -0500 Subject: [PATCH 03/11] minor fix --- stdlib/ctypes/__init__.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/stdlib/ctypes/__init__.pyi b/stdlib/ctypes/__init__.pyi index c64cee2791ca..19bd261c67e0 100644 --- a/stdlib/ctypes/__init__.pyi +++ b/stdlib/ctypes/__init__.pyi @@ -10,6 +10,7 @@ from _ctypes import ( _CArgObject as _CArgObject, _CData as _CData, _CDataType as _CDataType, + _CField as _CField, _CTypeBaseType, _Pointer as _Pointer, _PointerLike as _PointerLike, From ca3ee3497e2f38b477a8033eb55540a3645e7791 Mon Sep 17 00:00:00 2001 From: guoci Date: Wed, 19 Nov 2025 11:33:08 -0500 Subject: [PATCH 04/11] fix with `sys.version_info` --- stdlib/_ctypes.pyi | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/stdlib/_ctypes.pyi b/stdlib/_ctypes.pyi index 3f35c7d94700..37d1f63d56a5 100644 --- a/stdlib/_ctypes.pyi +++ b/stdlib/_ctypes.pyi @@ -197,16 +197,17 @@ _SetT = TypeVar("_SetT") @final class _CField(Generic[_CT, _GetT, _SetT]): - name: str - type: type[_CT] offset: int - byte_offset: int - byte_size: int size: int - is_bitfield: bool - bit_offset: int - bit_size: int - is_anonymous: bool + if sys.version_info >= (3, 14): + name: str + type: type[_CT] + byte_offset: int + byte_size: int + is_bitfield: bool + bit_offset: int + bit_size: int + is_anonymous: bool if sys.version_info >= (3, 10): @overload def __get__(self, instance: None, owner: type[Any] | None = None, /) -> Self: ... From bd3a7af3d82628224a1cfad61d96d2647528d7d3 Mon Sep 17 00:00:00 2001 From: guoci Date: Wed, 19 Nov 2025 11:55:17 -0500 Subject: [PATCH 05/11] fixes with `sys.version_info >= (3, 14)` --- stdlib/ctypes/__init__.pyi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stdlib/ctypes/__init__.pyi b/stdlib/ctypes/__init__.pyi index 19bd261c67e0..be2e7449ef31 100644 --- a/stdlib/ctypes/__init__.pyi +++ b/stdlib/ctypes/__init__.pyi @@ -55,6 +55,9 @@ if sys.version_info >= (3, 14): else: from _ctypes import POINTER as POINTER, pointer as pointer +if sys.version_info >= (3, 14): + CField = _CField + DEFAULT_MODE: Final[int] class ArgumentError(Exception): ... From 63f64849573fcc6c8437fb93d615cbb6fbbf2c28 Mon Sep 17 00:00:00 2001 From: guoci Date: Wed, 19 Nov 2025 12:00:39 -0500 Subject: [PATCH 06/11] fix with `TypeAlias` --- stdlib/_ctypes.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/_ctypes.pyi b/stdlib/_ctypes.pyi index 37d1f63d56a5..969a44f5b956 100644 --- a/stdlib/_ctypes.pyi +++ b/stdlib/_ctypes.pyi @@ -201,7 +201,7 @@ class _CField(Generic[_CT, _GetT, _SetT]): size: int if sys.version_info >= (3, 14): name: str - type: type[_CT] + type: TypeAlias = _CT byte_offset: int byte_size: int is_bitfield: bool From f24fe70d223111b8e992e53df21d7262e6dc6dcf Mon Sep 17 00:00:00 2001 From: guoci Date: Wed, 19 Nov 2025 17:18:24 -0500 Subject: [PATCH 07/11] fix issue --- stdlib/_ctypes.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/_ctypes.pyi b/stdlib/_ctypes.pyi index 969a44f5b956..37d1f63d56a5 100644 --- a/stdlib/_ctypes.pyi +++ b/stdlib/_ctypes.pyi @@ -201,7 +201,7 @@ class _CField(Generic[_CT, _GetT, _SetT]): size: int if sys.version_info >= (3, 14): name: str - type: TypeAlias = _CT + type: type[_CT] byte_offset: int byte_size: int is_bitfield: bool From da6c754c0e1e6a634804a707f64cf30a100737ff Mon Sep 17 00:00:00 2001 From: guoci Date: Thu, 20 Nov 2025 12:26:29 -0500 Subject: [PATCH 08/11] separate `_CField` classes, one for 3.14+ and one for < 3.14 --- stdlib/_ctypes.pyi | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/stdlib/_ctypes.pyi b/stdlib/_ctypes.pyi index 37d1f63d56a5..932881fb271a 100644 --- a/stdlib/_ctypes.pyi +++ b/stdlib/_ctypes.pyi @@ -195,11 +195,12 @@ class CFuncPtr(_PointerLike, _CData, metaclass=_PyCFuncPtrType): _GetT = TypeVar("_GetT") _SetT = TypeVar("_SetT") -@final -class _CField(Generic[_CT, _GetT, _SetT]): - offset: int - size: int - if sys.version_info >= (3, 14): +if sys.version_info >= (3, 14): + @final + @type_check_only + class _CField(Generic[_CT, _GetT, _SetT]): + offset: int + size: int name: str type: type[_CT] byte_offset: int @@ -208,18 +209,30 @@ class _CField(Generic[_CT, _GetT, _SetT]): bit_offset: int bit_size: int is_anonymous: bool - if sys.version_info >= (3, 10): @overload def __get__(self, instance: None, owner: type[Any] | None = None, /) -> Self: ... @overload def __get__(self, instance: Any, owner: type[Any] | None = None, /) -> _GetT: ... - else: - @overload - def __get__(self, instance: None, owner: type[Any] | None, /) -> Self: ... - @overload - def __get__(self, instance: Any, owner: type[Any] | None, /) -> _GetT: ... - def __set__(self, instance: Any, value: _SetT, /) -> None: ... + def __set__(self, instance: Any, value: _SetT, /) -> None: ... +else: + @final + @type_check_only + class _CField(Generic[_CT, _GetT, _SetT]): + offset: int + size: int + if sys.version_info >= (3, 10): + @overload + def __get__(self, instance: None, owner: type[Any] | None = None, /) -> Self: ... + @overload + def __get__(self, instance: Any, owner: type[Any] | None = None, /) -> _GetT: ... + else: + @overload + def __get__(self, instance: None, owner: type[Any] | None, /) -> Self: ... + @overload + def __get__(self, instance: Any, owner: type[Any] | None, /) -> _GetT: ... + + def __set__(self, instance: Any, value: _SetT, /) -> None: ... # This class is not exposed. It calls itself _ctypes.UnionType. @type_check_only From 808a641d64470a8684d44ecc89594ad6e479c838 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 20 Nov 2025 17:28:45 +0000 Subject: [PATCH 09/11] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/_ctypes.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/_ctypes.pyi b/stdlib/_ctypes.pyi index 932881fb271a..fcbabea0a60d 100644 --- a/stdlib/_ctypes.pyi +++ b/stdlib/_ctypes.pyi @@ -213,8 +213,8 @@ if sys.version_info >= (3, 14): def __get__(self, instance: None, owner: type[Any] | None = None, /) -> Self: ... @overload def __get__(self, instance: Any, owner: type[Any] | None = None, /) -> _GetT: ... - def __set__(self, instance: Any, value: _SetT, /) -> None: ... + else: @final @type_check_only From b3f1927f5ebbea314253d1cd549a51a2218ee2d6 Mon Sep 17 00:00:00 2001 From: guoci Date: Thu, 20 Nov 2025 12:57:53 -0500 Subject: [PATCH 10/11] fix --- stdlib/_ctypes.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/_ctypes.pyi b/stdlib/_ctypes.pyi index fcbabea0a60d..3be578910a14 100644 --- a/stdlib/_ctypes.pyi +++ b/stdlib/_ctypes.pyi @@ -198,7 +198,7 @@ _SetT = TypeVar("_SetT") if sys.version_info >= (3, 14): @final @type_check_only - class _CField(Generic[_CT, _GetT, _SetT]): + class CField(Generic[_CT, _GetT, _SetT]): offset: int size: int name: str @@ -214,6 +214,7 @@ if sys.version_info >= (3, 14): @overload def __get__(self, instance: Any, owner: type[Any] | None = None, /) -> _GetT: ... def __set__(self, instance: Any, value: _SetT, /) -> None: ... + _CField = CField else: @final From ccaba92a7d0048b3b79b65c4497bf86b473dae55 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 20 Nov 2025 18:00:12 +0000 Subject: [PATCH 11/11] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/_ctypes.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/stdlib/_ctypes.pyi b/stdlib/_ctypes.pyi index 3be578910a14..924df0e97dad 100644 --- a/stdlib/_ctypes.pyi +++ b/stdlib/_ctypes.pyi @@ -214,6 +214,7 @@ if sys.version_info >= (3, 14): @overload def __get__(self, instance: Any, owner: type[Any] | None = None, /) -> _GetT: ... def __set__(self, instance: Any, value: _SetT, /) -> None: ... + _CField = CField else: