coma.hooks.management¶
Utilities for managing recursive sequences of shared and command-specific hooks.
- class Hooks(parser_hook: Callable[[T], T | None] | HookSentinels | None | Sequence[Callable[[T], T | None] | HookSentinels | None] = None, pre_config_hook: Callable[[T], T | None] | HookSentinels | None | Sequence[Callable[[T], T | None] | HookSentinels | None] = None, config_hook: Callable[[T], T | None] | HookSentinels | None | Sequence[Callable[[T], T | None] | HookSentinels | None] = None, post_config_hook: Callable[[T], T | None] | HookSentinels | None | Sequence[Callable[[T], T | None] | HookSentinels | None] = None, pre_init_hook: Callable[[T], T | None] | HookSentinels | None | Sequence[Callable[[T], T | None] | HookSentinels | None] = None, init_hook: Callable[[T], T | None] | HookSentinels | None | Sequence[Callable[[T], T | None] | HookSentinels | None] = None, post_init_hook: Callable[[T], T | None] | HookSentinels | None | Sequence[Callable[[T], T | None] | HookSentinels | None] = None, pre_run_hook: Callable[[T], T | None] | HookSentinels | None | Sequence[Callable[[T], T | None] | HookSentinels | None] = None, run_hook: Callable[[T], T | None] | HookSentinels | None | Sequence[Callable[[T], T | None] | HookSentinels | None] = None, post_run_hook: Callable[[T], T | None] | HookSentinels | None | Sequence[Callable[[T], T | None] | HookSentinels | None] = None)[source]¶
A collection of all hooks that
comaaccepts.- static merge(shared_hooks: Hooks, command_hooks: Hooks) Hooks[source]¶
Returns a merged
Hookswhere theshared_hooksform the base and thecommand_hooks(which take precedence) are able to override this base.Specifically, each hook in
command_hookscan be either a plainHookOrSentinelsor aSequencethereof. If plain, the hook is transformed as below. If a sequence, each item in that sequence is recursively transformed as below, with the result being a new sequence of transformed items in the same order.Transformation process for a plain hook item in
command_hooks:1. If the hook is
None(notidentity()), then set the merged hook toidentityregardless of the value of the corresponding hook inshared_hooks.2. If the hook is the
SHAREDsentinel, then set the merged hook to the corresponding hook fromshared_hooks.3. If the hook is the
DEFAULTsentinel, then set the merged hook to the corresponding default hook regardless of the value of the corresponding hook inshared_hooks.4. For all other values of hook (including
identity), set the merged hook to said value (unchanged).When case (2) applies, the corresponding hook in
shared_hooksis also recursively transformed according to this process, that a shared hook cannot be set to theSHAREDsentinel to avoid infinite regress.- Returns:
The merged hooks.
- Return type:
- Raises:
ValueError – If a shared hook is or contains the
SHAREDsentinel.