You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Annotation-based decorator for ctypes function pointers #153903
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:
It would just be a nice-to-have if things like help() in the REPL (or ? in ipython) reproduced the docstring if one was provided on the stub. I think this could also be used by tools like sphinx. Whenever I write a decorator I tend to use functools.wraps, but I think the only relevant thing here is actually the .__doc__ member.
Activity
gh-153903: Add a `ctypes` decorator for generating function pointers …
pythongh-153903: Fix ctypes wrap_dll_function() with string annotations
gh-153903: Fix ctypes wrap_dll_function() with string annotations (#1…
gh-153903: Use `@ctypes.util.wrap_dll_function()` with pythonapi (#15…
gh-153903: Use `@ctypes.util.wrap_dll_function()` (#154122)
WardBrian commentedon Jul 21, 2026
It would also be nice if this propagated doc comments, which I don't believe gh-153904 does
ZeroIntensity commentedon Jul 21, 2026
Do you have a compelling use case for that?
WardBrian commentedon Jul 21, 2026
It would just be a nice-to-have if things like
help()in the REPL (or?in ipython) reproduced the docstring if one was provided on the stub. I think this could also be used by tools like sphinx. Whenever I write a decorator I tend to usefunctools.wraps, but I think the only relevant thing here is actually the.__doc__member.Currently, if you use the example in the docs:
help(PyObject_GetAttrString)would print the help forctypes._FuncPtr. It would be nice if a user could write something likeAnd have that string not just be swallowed/ignored
ZeroIntensity commentedon Jul 21, 2026
Seems reasonable. Would you like to submit a PR?
WardBrian commentedon Jul 21, 2026
Happy to!
gh-153903: Copy docstrings and other metadata in `ctypes.util.wrap_dl…
pythongh-153903: Copy docstrings and other metadata in `ctypes.util.w…