code: def _invoke_hook(hook_name, target):
      
      try:
          for value in getattr(target, hook_name):
              func, args, kwargs = value
              func(target, *args, **kwargs)
      except AttributeError:
          # no hook defined
          pass
      except (TypeError, ValueError):
          # hook not properly defined (might be a mock)
          pass
docs: Generic hook invocation.