MCPcopy Create free account
hub / github.com/BUPT-GAMMA/MASFactory / hook_register

Method hook_register

masfactory/core/node.py:357–393  ·  view source on GitHub ↗

Register a hook callback on this node. Args: hook_key: Hook stage key (see `Node.Hook`). func: Hook callback function. recursion: Reserved for API parity. Recursion is implemented by graphs/edges; a plain Node does not recurse into childre

(
        self,
        hook_key: object,
        func: Callable,
        recursion: bool = False,
        target_type: type | tuple[type, ...] | None = None,
        target_names: str | set[str] | list[str] | tuple[str, ...] | Callable[[str], bool] | None = None,
        target_filter: Callable[[object], bool] | None = None,
        selector: Selector | None = None,
    )

Source from the content-addressed store, hash-verified

355 def reset_gate(self):
356 self._gate = Gate.OPEN
357 def hook_register(
358 self,
359 hook_key: object,
360 func: Callable,
361 recursion: bool = False,
362 target_type: type | tuple[type, ...] | None = None,
363 target_names: str | set[str] | list[str] | tuple[str, ...] | Callable[[str], bool] | None = None,
364 target_filter: Callable[[object], bool] | None = None,
365 selector: Selector | None = None,
366 ) -> None:
367 """Register a hook callback on this node.
368
369 Args:
370 hook_key: Hook stage key (see `Node.Hook`).
371 func: Hook callback function.
372 recursion: Reserved for API parity. Recursion is implemented by graphs/edges; a plain
373 Node does not recurse into children.
374 target_type: Optional type filter used by the selector.
375 target_names: Optional name filter (exact, set, list/tuple, predicate).
376 target_filter: Optional predicate applied to the matched object.
377 selector: Optional explicit selector. When provided, it overrides `target_type/target_names/target_filter`.
378 """
379 # Use Node as the default selector type.
380 if target_type is None:
381 target_type = Node
382 predicate = None
383 if target_filter is not None:
384 predicate = lambda t: t.obj is not None and target_filter(t.obj)
385
386 selector = build_selector(
387 selector=selector,
388 type_filter=target_type,
389 name_filter=target_names,
390 predicate=predicate,
391 )
392 if selector.match(self):
393 self._hooks.register(hook_key, func)

Callers

nothing calls this directly

Calls 3

build_selectorFunction · 0.90
matchMethod · 0.80
registerMethod · 0.45

Tested by

no test coverage detected