<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def on_hook(self, hook):
 # type: (Hook) -> None """Takes a hook, and optionally calls hook.run on a function"""

        try:
            func, args_gen = self.hooked[type(hook)]
        except (KeyError, TypeError):
            return
        else:
            hook(func, args_gen())