Skip to content

Commit f73783d

Browse files
committed
wrap_dll_function: copy doc, etc from wrapped stub
1 parent 3479e45 commit f73783d

3 files changed

Lines changed: 5 additions & 0 deletions

File tree

Doc/library/ctypes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,7 @@ Specifying function pointers using type annotations
708708

709709
@wrap_dll_function(dll_to_wrap)
710710
def function_ptr_name(arg_name: ctypes_type, ...) -> ctypes_type:
711+
"""Optional docstring."""
711712
# There should be no body
712713
pass
713714

Lib/ctypes/util.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,8 @@ def decorator(func):
590590

591591
ptr.restype = restype
592592
ptr.argtypes = tuple(annotations.values())
593+
functools.update_wrapper(ptr, func, updated=())
594+
593595
return ptr
594596

595597
return decorator

Lib/test/test_ctypes/test_funcptr.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,14 @@ def test_abstract(self):
134134
def test_wrap_dll_function(self):
135135
@wrap_dll_function(ctypes.pythonapi)
136136
def PyObject_GetAttr(op: ctypes.py_object, attr: ctypes.py_object) -> ctypes.py_object:
137+
"""Call the PythonAPI function underlying getattr"""
137138
pass
138139

139140
class Foo:
140141
a = "abc"
141142

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

144146
with self.assertRaises(AttributeError):
145147
@wrap_dll_function(ctypes.pythonapi)

0 commit comments

Comments
 (0)