FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-153903: wrap_dll_function: copy doc, etc from wrapped stub by WardBrian · Pull Request #154495 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
3 changes: 1 addition & 2 deletions Doc/library/ctypes.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -708,8 +708,7 @@ Specifying function pointers using type annotations

@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
Expand Down
2 changes: 2 additions & 0 deletions Lib/ctypes/util.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL