Skip to content

ctypes: constructor of _FuncPointer can accept None to paramflags and Structure to iid in runtime - #9251

Closed
AmberAnsari89 wants to merge 4 commits into
python:mainfrom
AmberAnsari89:ctype_new_local_branch
Closed

AmberAnsari89 wants to merge 4 commits into
python:mainfrom
AmberAnsari89:ctype_new_local_branch

Conversation

@AmberAnsari89

Copy link
Copy Markdown
Contributor

fixes #8968

@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

comtypes (https://github.com/enthought/comtypes)
- comtypes/_memberspec.py:357: error: No overload variant of "_FuncPointer" matches argument types "int", "str", "None", "Optional[GUID]"  [call-overload]
- comtypes/_memberspec.py:357: note: Possible overload variants:
- comtypes/_memberspec.py:357: note:     def __init__(self, address: int) -> _FuncPointer
- comtypes/_memberspec.py:357: note:     def __init__(self, callable: Callable[..., Any]) -> _FuncPointer
- comtypes/_memberspec.py:357: note:     def __init__(self, func_spec: Tuple[Union[str, int], CDLL], paramflags: Tuple[Union[Tuple[int], Tuple[int, str], Tuple[int, str, Any]], ...] = ...) -> _FuncPointer
- comtypes/_memberspec.py:357: note:     def __init__(self, vtlb_index: int, name: str, paramflags: Tuple[Union[Tuple[int], Tuple[int, str], Tuple[int, str, Any]], ...] = ..., iid: _Pointer[c_int] = ...) -> _FuncPointer
- comtypes/_memberspec.py:358: error: No overload variant of "_FuncPointer" matches argument types "int", "str", "Optional[Tuple[Union[Tuple[int, Optional[str]], Tuple[int, Optional[str], Any]], ...]]", "Optional[GUID]"  [call-overload]
- comtypes/_memberspec.py:358: note: Possible overload variants:
- comtypes/_memberspec.py:358: note:     def __init__(self, address: int) -> _FuncPointer
- comtypes/_memberspec.py:358: note:     def __init__(self, callable: Callable[..., Any]) -> _FuncPointer
- comtypes/_memberspec.py:358: note:     def __init__(self, func_spec: Tuple[Union[str, int], CDLL], paramflags: Tuple[Union[Tuple[int], Tuple[int, str], Tuple[int, str, Any]], ...] = ...) -> _FuncPointer
- comtypes/_memberspec.py:358: note:     def __init__(self, vtlb_index: int, name: str, paramflags: Tuple[Union[Tuple[int], Tuple[int, str], Tuple[int, str, Any]], ...] = ..., iid: _Pointer[c_int] = ...) -> _FuncPointer

namespace: str | None = ...,
prefix: str | None = ...,
attrs: dict[str, str] | None = ...,
attrs: dict[str, Any] | None = ...,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave this change for another PR.

@JelleZijlstra

Copy link
Copy Markdown
Member

The ctypes code can be hard to follow, but I think there's more we can do here to improve things. The implementation of the code being changed here is at https://github.com/python/cpython/blob/8f18ac04d32515eab841172c956a8cb14bcee9c3/Modules/_ctypes/_ctypes.c#L3627.

  • Our stub has a _FuncPointer class that doesn't exist at runtime. But in fact, the code returns a subclass of _ctypes.CFuncPtr, so why don't we use that class in the stubs?
  • All of the arguments are positional-only and should be marked as such in the stub.
  • We're missing an overload for the case where no arguments are passed to the constructor.
  • The overload with vtbl_index (not vtlb_index as the stub calls it) should exist only on Windows.

@AmberAnsari89

Copy link
Copy Markdown
Contributor Author

thank you @JelleZijlstra for these information. However, i did not understand much from these.
Can you please guide me a bit more to understand with reference to actual requirement of issue under -- The constructor of _FuncPointer can accept None to paramflags and Structure to iid in runtime. #8968

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The constructor of _FuncPointer can accept None to paramflags and Structure to iid in runtime.

2 participants