Skip to content

move and rename from ctypes._FuncPointer to _ctypes.CFuncPtr #10140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions stdlib/_ctypes.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import sys
from _typeshed import ReadableBuffer, WriteableBuffer
from abc import abstractmethod
from collections.abc import Iterable, Iterator, Mapping, Sequence
from ctypes import CDLL
from typing import Any, Generic, TypeVar, overload
from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
from ctypes import CDLL, c_int
from typing import Any, ClassVar, Generic, TypeVar, overload
from typing_extensions import Self, TypeAlias

if sys.version_info >= (3, 9):
Expand Down Expand Up @@ -93,6 +93,24 @@ class _CArgObject: ...

def byref(obj: _CData, offset: int = ...) -> _CArgObject: ...

_ECT: TypeAlias = Callable[[type[_CData] | None, CFuncPtr, tuple[_CData, ...]], _CData]
_PF: TypeAlias = tuple[int] | tuple[int, str] | tuple[int, str, Any]

class CFuncPtr(_PointerLike, _CData):
restype: type[_CData] | Callable[[int], Any] | None
argtypes: Sequence[type[_CData]]
errcheck: _ECT
_flags_: ClassVar[int] # Abstract attribute that must be defined on subclasses
@overload
def __init__(self, address: int) -> None: ...
@overload
def __init__(self, callable: Callable[..., Any]) -> None: ...
@overload
def __init__(self, func_spec: tuple[str | int, CDLL], paramflags: tuple[_PF, ...] = ...) -> None: ...
@overload
def __init__(self, vtlb_index: int, name: str, paramflags: tuple[_PF, ...] = ..., iid: _Pointer[c_int] = ...) -> None: ...
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...

class _CField:
offset: int
size: int
Expand Down
21 changes: 3 additions & 18 deletions stdlib/ctypes/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ from _ctypes import (
RTLD_LOCAL as RTLD_LOCAL,
ArgumentError as ArgumentError,
Array as Array,
CFuncPtr as _CFuncPtr,
Structure as Structure,
Union as Union,
_CanCastTo as _CanCastTo,
Expand All @@ -26,8 +27,7 @@ from _ctypes import (
set_errno as set_errno,
sizeof as sizeof,
)
from collections.abc import Callable, Sequence
from typing import Any, ClassVar, Generic, TypeVar, overload
from typing import Any, ClassVar, Generic, TypeVar
from typing_extensions import TypeAlias

if sys.platform == "win32":
Expand Down Expand Up @@ -91,22 +91,7 @@ if sys.platform == "win32":
pydll: LibraryLoader[PyDLL]
pythonapi: PyDLL

_ECT: TypeAlias = Callable[[type[_CData] | None, _FuncPointer, tuple[_CData, ...]], _CData]
_PF: TypeAlias = tuple[int] | tuple[int, str] | tuple[int, str, Any]

class _FuncPointer(_PointerLike, _CData):
restype: type[_CData] | Callable[[int], Any] | None
argtypes: Sequence[type[_CData]]
errcheck: _ECT
@overload
def __init__(self, address: int) -> None: ...
@overload
def __init__(self, callable: Callable[..., Any]) -> None: ...
@overload
def __init__(self, func_spec: tuple[str | int, CDLL], paramflags: tuple[_PF, ...] = ...) -> None: ...
@overload
def __init__(self, vtlb_index: int, name: str, paramflags: tuple[_PF, ...] = ..., iid: _Pointer[c_int] = ...) -> None: ...
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
class _FuncPointer(_CFuncPtr): ...

class _NamedFuncPointer(_FuncPointer):
__name__: str
Expand Down
2 changes: 1 addition & 1 deletion tests/stubtest_allowlists/py3_common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ _collections_abc.Set.__rsub__
_collections_abc.Set.__rxor__

_csv.Dialect.__init__ # C __init__ signature is inaccurate
_ctypes.CFuncPtr # stubtest erroneously thinks it can't be subclassed
_threading_local.local.__new__
_weakref.ref.* # Alias for _weakref.ReferenceType, problems should be fixed there
_weakref.CallableProxyType.__getattr__ # Should have all attributes of proxy
Expand Down Expand Up @@ -334,7 +335,6 @@ turtle.ScrolledCanvas.onResize
wave.Wave_read.initfp
wave.Wave_write.initfp

_ctypes.CFuncPtr
_ctypes.PyObj_FromPtr
_ctypes.Py_DECREF
_ctypes.Py_INCREF
Expand Down