Feature or enhancement
Proposal:
The idea is to add a decorator that extracts type annotations and a name for a function signature, and then use that information to generate argtypes and restype for a _CFuncPtr object. For example:
@wrap_dll_function(ctypes.pythonapi) def PyObject_GetAttrString(op: ctypes.py_object, attr: ctypes.c_char_p) -> ctypes.py_object: ...
See #104533 for prior work.
Has this already been discussed elsewhere?
I have already discussed this feature proposal on Discourse
Links to previous discussion of this feature:
https://discuss.python.org/t/annotation-based-sugar-for-ctypes/26579
Linked PRs
- gh-153903: Add a
ctypesdecorator for generating function pointers using annotations #153904 - gh-153903: Use
@ctypes.util.wrap_dll_function()with pythonapi #154030 - gh-153903: Fix ctypes wrap_dll_function() with string annotations #154042
- gh-153903: Use
@ctypes.util.wrap_dll_function()#154122 - gh-153903: wrap_dll_function: copy doc, etc from wrapped stub #154495