gh-153903: Copy docstrings and other metadata in `ctypes.util.wrap_dl… · python/cpython@2b4e062

GitHub

Original file line numberDiff line numberDiff line change@@ -708,8 +708,7 @@ Specifying function pointers using type annotations

708708709709 @wrap_dll_function(dll_to_wrap)

710710 def function_ptr_name(arg_name: ctypes_type, ...) -> ctypes_type:

711- # There should be no body

712- pass

711+ """Optional docstring. There should be no function body."""

713712714713 The body of the decorated function is ignored, and any parameters that are

715714 missing type annotations are skipped. The names of the parameters are ignored

Original file line numberDiff line numberDiff line change@@ -590,6 +590,8 @@ def decorator(func):

590590591591ptr.restype=restype

592592ptr.argtypes=tuple(annotations.values())

593+functools.update_wrapper(ptr, func, updated=())

594+593595returnptr

594596595597returndecorator

Original file line numberDiff line numberDiff line change@@ -134,12 +134,14 @@ def test_abstract(self):

134134deftest_wrap_dll_function(self):

135135@wrap_dll_function(ctypes.pythonapi)

136136defPyObject_GetAttr(op: ctypes.py_object, attr: ctypes.py_object) ->ctypes.py_object:

137+"""Call the PythonAPI function underlying getattr"""

137138pass

138139139140classFoo:

140141a="abc"

141142142143self.assertEqual(PyObject_GetAttr(Foo, "a"), "abc")

144+self.assertEqual(PyObject_GetAttr.__doc__, "Call the PythonAPI function underlying getattr")

143145144146withself.assertRaises(AttributeError):

145147@wrap_dll_function(ctypes.pythonapi)