File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -579,7 +579,7 @@ def wrap_dll_function(dll):
579579 def decorator (func ):
580580 name = func .__name__
581581 ptr = getattr (dll , name )
582- annotations = annotationlib .get_annotations (func )
582+ annotations = annotationlib .get_annotations (func , eval_str = True )
583583
584584 try :
585585 restype = annotations .pop ("return" )
Original file line number Diff line number Diff line change @@ -151,6 +151,11 @@ def noexist():
151151 def PyObject_GetAttrString (op : ctypes .py_object , attr : ctypes .c_char_p ):
152152 pass
153153
154+ def test_wrap_dll_function_str_ann (self ):
155+ from test .test_ctypes import wrap_str_ann
156+ version = wrap_str_ann .Py_GetVersion ()
157+ self .assertIsInstance (version , bytes )
158+
154159
155160if __name__ == '__main__' :
156161 unittest .main ()
Original file line number Diff line number Diff line change 1+ from __future__ import annotations
2+ import ctypes .util
3+
4+ def test_ann () -> ctypes .c_char_p :
5+ ...
6+
7+ # Check that "from __future__ import annotations" works as expected
8+ if not isinstance (test_ann .__annotations__ ['return' ], str ):
9+ raise Exception ("annotations must be strings" )
10+
11+ @ctypes .util .wrap_dll_function (ctypes .pythonapi )
12+ def Py_GetVersion () -> ctypes .c_char_p :
13+ ...
You can’t perform that action at this time.
0 commit comments