8000 ctypes: constructor of _FuncPointer can accept None to paramflags and Structure to iid in runtime by AmberAnsari89 · Pull Request #9251 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

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

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

Closed

Conversation

AmberAnsari89
Copy link
Contributor

fixes #8968

@github-actions
Copy link
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

@@ -247,7 +247,7 @@ class Tag(PageElement):
name: str | None = ...,
namespace: str | None = ...,
prefix: str | None = ...,
attrs: dict[str, str] | None = ...,
attrs: dict[str, Any] | None = ...,
Copy link
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
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
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
0