Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
@wrap_dll_function(dll_to_wrap)
def function_ptr_name(arg_name: ctypes_type, ...) -> ctypes_type:
- # There should be no body
- pass
+ """Optional docstring. There should be no function body."""
The body of the decorated function is ignored, and any parameters that are
missing type annotations are skipped. The names of the parameters are ignored
ptr.restype = restype
ptr.argtypes = tuple(annotations.values())
+ functools.update_wrapper(ptr, func, updated=())
+
return ptr
return decorator
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)