Skip to content

Commit d0ce310

Browse files
sobolevnAkuli
andauthored
Make ctypes.Array abstract (#6361)
Co-authored-by: Akuli <[email protected]>
1 parent 77d820c commit d0ce310

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

stdlib/ctypes/__init__.pyi

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sys
22
from _typeshed import ReadableBuffer, WriteableBuffer
3+
from abc import abstractmethod
34
from typing import (
45
Any,
56
Callable,
@@ -268,8 +269,16 @@ class BigEndianStructure(Structure): ...
268269
class LittleEndianStructure(Structure): ...
269270

270271
class Array(Generic[_CT], _CData):
271-
_length_: int
272-
_type_: Type[_CT]
272+
@property
273+
@abstractmethod
274+
def _length_(self) -> int: ...
275+
@_length_.setter
276+
def _length_(self, value: int) -> None: ...
277+
@property
278+
@abstractmethod
279+
def _type_(self) -> Type[_CT]: ...
280+
@_type_.setter
281+
def _type_(self, value: Type[_CT]) -> None: ...
273282
raw: bytes # Note: only available if _CT == c_char
274283
value: Any # Note: bytes if _CT == c_char, str if _CT == c_wchar, unavailable otherwise
275284
# TODO These methods cannot be annotated correctly at the moment.

tests/stubtest_allowlists/py3_common.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ csv.Dialect.lineterminator
7373
csv.Dialect.quoting
7474
csv.Dialect.skipinitialspace
7575
ctypes.Array.__iter__ # mypy doesn't support using __getitem__ instead of __iter__ so this is here https://github.com/python/mypy/issues/2220
76+
ctypes.Array._type_ # _type_ and _length_ are abstract, https://github.com/python/typeshed/pull/6361
77+
ctypes.Array._length_
7678
ctypes.CDLL._FuncPtr # None at class level but initialized in __init__ to this value
7779
ctypes.memmove # CFunctionType
7880
ctypes.memset # CFunctionType

0 commit comments

Comments
 (0)