HookHandle#

class brainstate.HookHandle(manager_ref, hook, hook_type)[source]#

Handle for managing a registered hook.

This handle provides methods to enable, disable, and remove hooks without directly accessing the HookManager.

Examples

>>> state = bst.State(0, enable_hooks=True)
>>> handle = state.register_hook('read', lambda ctx: print(ctx.value))
>>> handle.disable()
>>> state.value  # Hook not executed
>>> handle.enable()
>>> state.value  # Hook executed
>>> handle.remove()  # Permanently unregister
disable()[source]#

Disable the hook.

Raises:

HookError – If the hook has been removed or the manager is gone

Return type:

None

enable()[source]#

Enable the hook.

Raises:

HookError – If the hook has been removed or the manager is gone

Return type:

None

is_enabled()[source]#

Check if the hook is currently enabled.

Return type:

bool

is_removed()[source]#

Check if the hook has been removed.

Return type:

bool

property name: str#

Get the hook’s name.

property priority: int#

Get the hook’s priority.

remove()[source]#

Remove the hook permanently.

Return type:

bool