Skip to content

Commit 3f3fe64

Browse files
committed
ctypes: replace type-check-only mixin with direct __dtype_{be,le}__ class attr declarations
1 parent 7eb3501 commit 3f3fe64

File tree

1 file changed

+73
-30
lines changed

1 file changed

+73
-30
lines changed

stdlib/ctypes/__init__.pyi

Lines changed: 73 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -219,96 +219,139 @@ class py_object(_CanCastTo, _SimpleCData[_T]):
219219
if sys.version_info >= (3, 14):
220220
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
221221

222-
@type_check_only
223-
class _SwappableCData:
222+
class c_bool(_SimpleCData[bool]):
223+
_type_: ClassVar[Literal["?"]]
224224
__ctype_be__: ClassVar[type[Self]]
225225
__ctype_le__: ClassVar[type[Self]]
226-
227-
class c_bool(_SimpleCData[bool], _SwappableCData):
228-
_type_: ClassVar[Literal["?"]]
229226
def __init__(self, value: SupportsBool | SupportsLen | None = ...) -> None: ...
230227

231-
class c_byte(_SimpleCData[int], _SwappableCData):
228+
class c_byte(_SimpleCData[int]):
232229
_type_: ClassVar[Literal["b"]]
230+
__ctype_be__: ClassVar[type[Self]]
231+
__ctype_le__: ClassVar[type[Self]]
233232

234-
class c_ubyte(_SimpleCData[int], _SwappableCData):
233+
class c_ubyte(_SimpleCData[int]):
235234
_type_: ClassVar[Literal["B"]]
235+
__ctype_be__: ClassVar[type[Self]]
236+
__ctype_le__: ClassVar[type[Self]]
236237

237-
class c_short(_SimpleCData[int], _SwappableCData):
238+
class c_short(_SimpleCData[int]):
238239
_type_: ClassVar[Literal["h"]]
240+
__ctype_be__: ClassVar[type[Self]]
241+
__ctype_le__: ClassVar[type[Self]]
239242

240-
class c_ushort(_SimpleCData[int], _SwappableCData):
243+
class c_ushort(_SimpleCData[int]):
241244
_type_: ClassVar[Literal["H"]]
245+
__ctype_be__: ClassVar[type[Self]]
246+
__ctype_le__: ClassVar[type[Self]]
242247

243-
class c_long(_SimpleCData[int], _SwappableCData):
248+
class c_long(_SimpleCData[int]):
244249
_type_: ClassVar[Literal["l"]]
250+
__ctype_be__: ClassVar[type[Self]]
251+
__ctype_le__: ClassVar[type[Self]]
245252

246-
class c_ulong(_SimpleCData[int], _SwappableCData):
253+
class c_ulong(_SimpleCData[int]):
247254
_type_: ClassVar[Literal["L"]]
255+
__ctype_be__: ClassVar[type[Self]]
256+
__ctype_le__: ClassVar[type[Self]]
248257

249-
class c_int(_SimpleCData[int], _SwappableCData): # can be an alias for c_long
258+
class c_int(_SimpleCData[int]): # can be an alias for c_long
250259
_type_: ClassVar[Literal["i", "l"]]
260+
__ctype_be__: ClassVar[type[Self]]
261+
__ctype_le__: ClassVar[type[Self]]
251262

252-
class c_uint(_SimpleCData[int], _SwappableCData): # can be an alias for c_ulong
263+
class c_uint(_SimpleCData[int]): # can be an alias for c_ulong
253264
_type_: ClassVar[Literal["I", "L"]]
265+
__ctype_be__: ClassVar[type[Self]]
266+
__ctype_le__: ClassVar[type[Self]]
254267

255-
class c_longlong(_SimpleCData[int], _SwappableCData): # can be an alias for c_long
268+
class c_longlong(_SimpleCData[int]): # can be an alias for c_long
256269
_type_: ClassVar[Literal["q", "l"]]
270+
__ctype_be__: ClassVar[type[Self]]
271+
__ctype_le__: ClassVar[type[Self]]
257272

258-
class c_ulonglong(_SimpleCData[int], _SwappableCData): # can be an alias for c_ulong
273+
class c_ulonglong(_SimpleCData[int]): # can be an alias for c_ulong
259274
_type_: ClassVar[Literal["Q", "L"]]
275+
__ctype_be__: ClassVar[type[Self]]
276+
__ctype_le__: ClassVar[type[Self]]
260277

261278
c_int8 = c_byte
262279
c_uint8 = c_ubyte
263280

264-
class c_int16(_SimpleCData[int], _SwappableCData): # can be an alias for c_short or c_int
281+
class c_int16(_SimpleCData[int]): # can be an alias for c_short or c_int
265282
_type_: ClassVar[Literal["h", "i"]]
283+
__ctype_be__: ClassVar[type[Self]]
284+
__ctype_le__: ClassVar[type[Self]]
266285

267-
class c_uint16(_SimpleCData[int], _SwappableCData): # can be an alias for c_ushort or c_uint
286+
class c_uint16(_SimpleCData[int]): # can be an alias for c_ushort or c_uint
268287
_type_: ClassVar[Literal["H", "I"]]
288+
__ctype_be__: ClassVar[type[Self]]
289+
__ctype_le__: ClassVar[type[Self]]
269290

270-
class c_int32(_SimpleCData[int], _SwappableCData): # can be an alias for c_int or c_long
291+
class c_int32(_SimpleCData[int]): # can be an alias for c_int or c_long
271292
_type_: ClassVar[Literal["i", "l"]]
293+
__ctype_be__: ClassVar[type[Self]]
294+
__ctype_le__: ClassVar[type[Self]]
272295

273-
class c_uint32(_SimpleCData[int], _SwappableCData): # can be an alias for c_uint or c_ulong
296+
class c_uint32(_SimpleCData[int]): # can be an alias for c_uint or c_ulong
274297
_type_: ClassVar[Literal["I", "L"]]
298+
__ctype_be__: ClassVar[type[Self]]
299+
__ctype_le__: ClassVar[type[Self]]
275300

276-
class c_int64(_SimpleCData[int], _SwappableCData): # can be an alias for c_long or c_longlong
301+
class c_int64(_SimpleCData[int]): # can be an alias for c_long or c_longlong
277302
_type_: ClassVar[Literal["l", "q"]]
303+
__ctype_be__: ClassVar[type[Self]]
304+
__ctype_le__: ClassVar[type[Self]]
278305

279-
class c_uint64(_SimpleCData[int], _SwappableCData): # can be an alias for c_ulong or c_ulonglong
306+
class c_uint64(_SimpleCData[int]): # can be an alias for c_ulong or c_ulonglong
280307
_type_: ClassVar[Literal["L", "Q"]]
308+
__ctype_be__: ClassVar[type[Self]]
309+
__ctype_le__: ClassVar[type[Self]]
281310

282-
class c_ssize_t(_SimpleCData[int], _SwappableCData): # alias for c_int, c_long, or c_longlong
311+
class c_ssize_t(_SimpleCData[int]): # alias for c_int, c_long, or c_longlong
283312
_type_: ClassVar[Literal["i", "l", "q"]]
313+
__ctype_be__: ClassVar[type[Self]]
314+
__ctype_le__: ClassVar[type[Self]]
284315

285-
class c_size_t(_SimpleCData[int], _SwappableCData): # alias for c_uint, c_ulong, or c_ulonglong
316+
class c_size_t(_SimpleCData[int]): # alias for c_uint, c_ulong, or c_ulonglong
286317
_type_: ClassVar[Literal["I", "L", "Q"]]
318+
__ctype_be__: ClassVar[type[Self]]
319+
__ctype_le__: ClassVar[type[Self]]
287320

288-
class c_float(_SimpleCData[float], _SwappableCData):
321+
class c_float(_SimpleCData[float]):
289322
_type_: ClassVar[Literal["f"]]
323+
__ctype_be__: ClassVar[type[Self]]
324+
__ctype_le__: ClassVar[type[Self]]
290325

291-
class c_double(_SimpleCData[float], _SwappableCData):
326+
class c_double(_SimpleCData[float]):
292327
_type_: ClassVar[Literal["d"]]
328+
__ctype_be__: ClassVar[type[Self]]
329+
__ctype_le__: ClassVar[type[Self]]
293330

294-
class c_longdouble(_SimpleCData[float], _SwappableCData): # can be an alias for c_double
331+
class c_longdouble(_SimpleCData[float]): # can be an alias for c_double
295332
_type_: ClassVar[Literal["d", "g"]]
296333

297334
if sys.version_info >= (3, 14) and sys.platform != "win32":
298335
# NOTE: currently (3.14.4) the `__ctype_{be,le}__` attributes of these complex types are missing at runtime:
299336
# https://github.com/python/cpython/issues/148464
300337

301-
class c_double_complex(_SimpleCData[complex], _SwappableCData):
338+
class c_double_complex(_SimpleCData[complex]):
302339
_type_: ClassVar[Literal["D"]]
340+
__ctype_be__: ClassVar[type[Self]]
341+
__ctype_le__: ClassVar[type[Self]]
303342

304-
class c_float_complex(_SimpleCData[complex], _SwappableCData):
343+
class c_float_complex(_SimpleCData[complex]):
305344
_type_: ClassVar[Literal["F"]]
345+
__ctype_be__: ClassVar[type[Self]]
346+
__ctype_le__: ClassVar[type[Self]]
306347

307-
class c_longdouble_complex(_SimpleCData[complex], _SwappableCData):
348+
class c_longdouble_complex(_SimpleCData[complex]):
308349
_type_: ClassVar[Literal["G"]]
309350

310-
class c_char(_SimpleCData[bytes], _SwappableCData):
351+
class c_char(_SimpleCData[bytes]):
311352
_type_: ClassVar[Literal["c"]]
353+
__ctype_be__: ClassVar[type[Self]]
354+
__ctype_le__: ClassVar[type[Self]]
312355
def __init__(self, value: int | bytes | bytearray = ...) -> None: ...
313356

314357
class c_char_p(_PointerLike, _SimpleCData[bytes | None]):

0 commit comments

Comments
 (0)