Skip to content
Open
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
1 change: 1 addition & 0 deletions Doc/library/ctypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ Specifying function pointers using type annotations

@wrap_dll_function(dll_to_wrap)
def function_ptr_name(arg_name: ctypes_type, ...) -> ctypes_type:
"""Optional docstring."""
# There should be no body
pass

Expand Down
2 changes: 2 additions & 0 deletions Lib/ctypes/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,8 @@ def decorator(func):

ptr.restype = restype
ptr.argtypes = tuple(annotations.values())
functools.update_wrapper(ptr, func, updated=())

return ptr

return decorator
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_ctypes/test_funcptr.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,14 @@ def test_abstract(self):
def test_wrap_dll_function(self):
@wrap_dll_function(ctypes.pythonapi)
def PyObject_GetAttr(op: ctypes.py_object, attr: ctypes.py_object) -> ctypes.py_object:
"""Call the PythonAPI function underlying getattr"""
pass

class Foo:
a = "abc"

self.assertEqual(PyObject_GetAttr(Foo, "a"), "abc")
self.assertEqual(PyObject_GetAttr.__doc__, "Call the PythonAPI function underlying getattr")

with self.assertRaises(AttributeError):
@wrap_dll_function(ctypes.pythonapi)
Expand Down
Loading