Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Lib/ctypes/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ def wrap_dll_function(dll):
def decorator(func):
name = func.__name__
ptr = getattr(dll, name)
annotations = annotationlib.get_annotations(func)
annotations = annotationlib.get_annotations(func, eval_str=True)

try:
restype = annotations.pop("return")
Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_ctypes/test_funcptr.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ def noexist():
def PyObject_GetAttrString(op: ctypes.py_object, attr: ctypes.c_char_p):
pass

def test_wrap_dll_function_str_ann(self):
from test.test_ctypes import wrap_str_ann
version = wrap_str_ann.Py_GetVersion()
self.assertIsInstance(version, bytes)


if __name__ == '__main__':
unittest.main()
13 changes: 13 additions & 0 deletions Lib/test/test_ctypes/wrap_str_ann.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from __future__ import annotations
import ctypes.util

def test_ann() -> ctypes.c_char_p:
...

# Check that "from __future__ import annotations" works as expected
if not isinstance(test_ann.__annotations__['return'], str):
raise Exception("annotations must be strings")

@ctypes.util.wrap_dll_function(ctypes.pythonapi)
def Py_GetVersion() -> ctypes.c_char_p:
...
Loading