code: def on_hook(self, hook):
          # type: (Hook) -> None
          
          try:
              func, args_gen = self.hooked[type(hook)]
          except (KeyError, TypeError):
              return
          else:
              hook(func, args_gen())
docs: Takes a hook, and optionally calls hook.run on a function