Skip to content

detached

detached #

cg.detached() — allow node construction that is collected nowhere.

The strict rule is that constructing a procedure node needs an active context. cg.detached() satisfies that for standalone construction — building a node to inspect it in a test, or assembling one outside a @cg.procedure body — while collecting nothing and recording no structure.

DetachedContext #

Bases: ProcedureContext

A context that permits construction but collects and reduces nothing.

Source code in capturegraph-lib/capturegraph/procedures/procedure/authoring/contexts/detached.py
class DetachedContext(ProcedureContext):
    """A context that permits construction but collects and reduces nothing."""

    def _collect(self, node: Procedure[CGType]) -> None:
        pass

    def _finish(self) -> None:
        pass

detached() #

Permit standalone node construction; nothing is collected or recorded.

Source code in capturegraph-lib/capturegraph/procedures/procedure/authoring/contexts/detached.py
@contextmanager
def detached() -> Iterator[None]:
    """Permit standalone node construction; nothing is collected or recorded."""
    with DetachedContext().collect():
        yield