class_docstr: TaskHooks can handle some tasks during the spectific event.
class_docstr_tok: ["TaskHooks","can","handle","some","tasks","during","the","spectific","event","."]
docstr: add the handler function to spectific event.
  Args:
      hook_type (str): the spectific event name
      name (str): the handler function name, default None
      func (func): the handler function, default None
docstr_tok: ["add","the","handler","function","to","spectific","event",".","Args",":","hook_type","(","str",")",":","the","spectific","event","name","name","(","str",")",":","the","handler","function","name",",","default","None","func","(","func",")",":","the","handler","function",",","default","None"]
code: def add(
      self, hook_type: str, name: str = None, func: Callable = None
  ):
      """
      add the handler function to spectific event.
      Args:
          hook_type (str): the spectific event name
          name (str): the handler function name, default None
          func (func): the handler function, default None
      """
      if not func or not callable(func):
          raise TypeError(
              "The hook function is empty or it is not a function"
          )
      if name == None:
          name = "hook_%s" % id(func)
  
      # check validity
      if not isinstance(name, str) or name.strip() == "":
          raise TypeError("The hook name must be a non-empty string")
      if hook_type not in self._registered_hooks:
          raise ValueError("hook_type: %s does not exist" % (hook_type))
      if name in self._registered_hooks[hook_type]:
          raise ValueError(
              "name: %s has existed in hook_type:%s, use modify method to modify it"
              % (name, hook_type)
          )
      else:
          args_num = len(inspect.getfullargspec(func).args)
          if args_num != self._hook_params_num[hook_type]:
              raise ValueError(
                  "The number of parameters to the hook hook_type:%s should be %i"
                  % (hook_type, self._hook_params_num[hook_type])
              )
          self._registered_hooks[hook_type][name] = func
  
file_path: PaddleHub/paddlehub/compat/task/hook.py
imports: import inspect
  from collections import OrderedDict
  from typing import Callable
label_desc: Use image node_id 2 for calling the TaskHooks obj's underlying member method code with example usage: obj.add(hook_type, name, func) without return types