code: def _cfactory(attr, func, argtypes, restype, errcheck=None):
          # type: (Any, str, List[Any], Any, Optional[Callable]) -> None
          
  
          meth = getattr(attr, func)
          meth.argtypes = argtypes
          meth.restype = restype
          if errcheck:
              meth.errcheck = errcheck
docs: Factory to create a ctypes function and automatically manage errors.