From e6736cde8dba9b0053da24de8e599ef990c14ca4 Mon Sep 17 00:00:00 2001 From: Joshua Oreman Date: Fri, 10 Jul 2020 01:44:23 -0700 Subject: [PATCH] ctypes: allow cast() 1st argument to be int and 2nd argument to be Type[py_object] (#4311) --- stdlib/2and3/ctypes/__init__.pyi | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/stdlib/2and3/ctypes/__init__.pyi b/stdlib/2and3/ctypes/__init__.pyi index 0793081f6..04ed34c35 100644 --- a/stdlib/2and3/ctypes/__init__.pyi +++ b/stdlib/2and3/ctypes/__init__.pyi @@ -96,7 +96,8 @@ class _CData(metaclass=_CDataMeta): @classmethod def in_dll(cls: Type[_CT], library: CDLL, name: str) -> _CT: ... -class _PointerLike(_CData): ... +class _CanCastTo(_CData): ... +class _PointerLike(_CanCastTo): ... _ECT = Callable[[Optional[Type[_CData]], _FuncPointer, Tuple[_CData, ...]], _CData] _PF = _UnionT[Tuple[int], Tuple[int, str], Tuple[int, str, Any]] @@ -143,9 +144,9 @@ def addressof(obj: _CData) -> int: ... def alignment(obj_or_type: _UnionT[_CData, Type[_CData]]) -> int: ... def byref(obj: _CData, offset: int = ...) -> _CArgObject: ... -_PT = TypeVar("_PT", bound=_PointerLike) +_CastT = TypeVar("_CastT", bound=_CanCastTo) -def cast(obj: _UnionT[_CData, _CArgObject], type: Type[_PT]) -> _PT: ... +def cast(obj: _UnionT[_CData, _CArgObject, int], type: Type[_CastT]) -> _CastT: ... def create_string_buffer(init_or_size: _UnionT[int, bytes], size: Optional[int] = ...) -> Array[c_char]: ... c_buffer = create_string_buffer @@ -247,7 +248,7 @@ class c_bool(_SimpleCData[bool]): if sys.platform == "win32": class HRESULT(_SimpleCData[int]): ... # TODO undocumented -class py_object(_SimpleCData[_T]): ... +class py_object(_CanCastTo, _SimpleCData[_T]): ... class _CField: offset: int = ...