-
Notifications
You must be signed in to change notification settings - Fork 330
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Describe the solution you'd like
pyglet.gl.gl* funcs have no popup hint of arguments
here is my code example to use annotations which will work as IDE hint and ctypes configurator
dlls_by_name = {}
def dll_import(dll_name):
"""
decorator for import DLL func.
always annotate return type even if it is None !
"""
dll_name = str(dll_name)
def decorator(func):
dll_func = None
def wrapper(*args):
nonlocal dll_func
if dll_func is None:
dll = dlls_by_name.get(dll_name, None)
if dll is None:
try:
dll = ctypes.cdll.LoadLibrary(find_library(dll_name))
except:
pass
if dll is None:
raise RuntimeError(f'Unable to load {dll_name} library.')
dlls_by_name[dll_name] = dll
dll_func = getattr(dll, func.__name__)
anno = list(get_type_hints(func).values())
anno = [ None if x is type(None) else x for x in anno ]
dll_func.argtypes = anno[:-1]
dll_func.restype = anno[-1]
return dll_func(*args)
return wrapper
return decorator
@dll_import('OpenCL')
def clGetPlatformIDs (num_entries : cl_uint, platforms : POINTER(cl_platform_id), num_platforms : POINTER(cl_uint) ) -> cl_result: ...
Could probably be improved.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
