Skip to content

initialization

initialization #

Construction and subclassing hooks bound onto Procedure.

__post_init__ runs after every node's dataclass __init__ in one fixed order: stamp identity, resolve the return type, validate the node, register it with the active recording context. A node customizes only the middle step, by overriding _resolve_type — never by choosing where to call super(). __init_subclass__ records each subclass's declared return type.

__init_subclass__(cls) #

Record the subclass's return type from its Procedure[X] base.

Source code in capturegraph-lib/capturegraph/procedures/procedure/methods/initialization.py
def __init_subclass__(cls: type[Procedure]) -> None:
    """Record the subclass's return type from its ``Procedure[X]`` base."""
    from capturegraph.procedures.procedure import (
        Procedure,
    )

    super(Procedure, cls).__init_subclass__()
    declared = returns.declared_return_type(cls)
    if declared is not None:
        cls.declared_return_type = declared

__post_init__(self) #

Stamp identity, resolve the type, type-check the node, and register it.

Constructing a node registers it with the active recording context (which is how a procedure body is built — see capturegraph.procedures.procedure.authoring.contexts). There must be one: a node built with no active context raises, unless under cg.detached().

Source code in capturegraph-lib/capturegraph/procedures/procedure/methods/initialization.py
def __post_init__(self: Procedure) -> None:
    """Stamp identity, resolve the type, type-check the node, and register it.

    Constructing a node registers it with the active recording context (which
    is how a procedure body is built — see
    [capturegraph.procedures.procedure.authoring.contexts][]). There must be one: a node
    built with no active context raises, unless under ``cg.detached()``.
    """
    object.__setattr__(self, "_uuid", _new_uuid())
    object.__setattr__(self, "_children", {})
    resolved = self._resolve_type()
    object.__setattr__(
        self,
        "_return_type",
        type(self).declared_return_type if resolved is None else resolved,
    )
    validation.validate(self)
    from capturegraph.procedures.procedure.authoring.contexts.base import (
        ProcedureContext,
    )

    ProcedureContext.current()._collect(self)