33import os
44import platform
55import struct
6+ from typing import Optional , Protocol , Type
67
78# Set up logger
89logger = logging .getLogger (__name__ )
3132 }
3233
3334
35+ class CFuncTypeFactory (Protocol ):
36+ """Protocol for ctypes function type factories (CFUNCTYPE/WINFUNCTYPE)."""
37+
38+ def __call__ (
39+ self ,
40+ restype : Optional [type ],
41+ * argtypes : type ,
42+ use_errno : bool = ...,
43+ use_last_error : bool = ...,
44+ ) -> Type [ctypes ._CFuncPtr ]: # pyright: ignore[reportAttributeAccessIssue]
45+ ...
46+
47+
3448class LibraryLoadError (OSError ):
3549 pass
3650
@@ -56,7 +70,7 @@ def load_library(library, x86_path=".", x64_path=".", arm64_path=None, *args, **
5670 raise LibraryLoadError (f"unable to load { library !r} . Provided library path: { lib !r} " )
5771
5872
59- def _do_load (file , * args , ** kwargs ):
73+ def _do_load (file , * args , ** kwargs ) -> Optional [ ctypes . CDLL ] :
6074 system = platform .system ()
6175 logger .debug ("Using loader for system: %s" , system )
6276 loader = TYPES [system ]["loader" ]
@@ -67,7 +81,7 @@ def _do_load(file, *args, **kwargs):
6781 return None
6882
6983
70- def find_library_path (libname , x86_path = "." , x64_path = "." , arm64_path = None ):
84+ def find_library_path (libname , x86_path = "." , x64_path = "." , arm64_path = None ) -> str :
7185 system = platform .system ()
7286 prefix = TYPES [system ]["prefix" ]
7387 libname_with_prefix = f"{ prefix } { libname } "
@@ -111,9 +125,9 @@ def find_library_path(libname, x86_path=".", x64_path=".", arm64_path=None):
111125 return abs_path
112126
113127
114- def get_functype ():
128+ def get_functype () -> CFuncTypeFactory :
115129 return TYPES [platform .system ()]["functype" ]
116130
117131
118- def get_library_extension ():
132+ def get_library_extension () -> str :
119133 return TYPES [platform .system ()]["extension" ]
0 commit comments