Skip to content

state

state #

ProcedureState — a node's private, non-field state.

Kept off the dataclass (a plain base class of Procedure) so none of it enters the constructor or __dataclass_fields__.

ProcedureState #

A node's identity and per-slot authoring state.

A node's return type has two names, and neither shadows the other: declared_return_type is the class-level X from the Procedure[X] base, and _return_type is the instance's actual type, stamped once in __post_init__ from _resolve_type() and read through return_type. _uuid is likewise set per instance.

_children and _assigned_value carry per-slot authoring state on the node itself (no global bookkeeping): the memoized navigation children — a non-empty dict marks the slot a container — and the procedure cached at this slot, or None. A slot is a value or a container, not both.

The immutability rule lives here too: nodes are frozen, so the only write a node accepts is the |= / &= cache rebind (see methods.navigation).

Source code in capturegraph-lib/capturegraph/procedures/procedure/methods/state.py
class ProcedureState:
    """A node's identity and per-slot authoring state.

    A node's return type has two names, and neither shadows the other:
    ``declared_return_type`` is the class-level ``X`` from the ``Procedure[X]``
    base, and ``_return_type`` is the instance's actual type, stamped once in
    ``__post_init__`` from ``_resolve_type()`` and read through ``return_type``.
    ``_uuid`` is likewise set per instance.

    ``_children`` and ``_assigned_value`` carry per-slot authoring state on the
    node itself (no global bookkeeping): the memoized navigation children — a
    non-empty dict marks the slot a *container* — and the procedure cached at
    this slot, or ``None``. A slot is a value or a container, not both.

    The immutability rule lives here too: nodes are frozen, so the only write a
    node accepts is the ``|=`` / ``&=`` cache rebind (see
    [methods.navigation][capturegraph.procedures.procedure.methods.navigation]).
    """

    from capturegraph.procedures.procedure.methods.navigation import (
        __setattr__ as __setattr__,
    )

    _uuid: str
    _return_type: type[CGType]
    declared_return_type: ClassVar[type[CGType]] = CGType
    _children: dict[tuple[object, ...], Procedure[CGType]]
    _assigned_value: Procedure[CGType] | None = None

    @property
    def uuid(self) -> str:
        """This node's unique id (DAG identity / serialization key)."""
        return self._uuid

    @property
    def return_type(self) -> type[CGType]:
        """The ``CGType`` this node produces when executed."""
        return self._return_type

    @property
    def kind(self) -> type[Self]:
        """This node's class — its name is the JSON ``"kind"``."""
        return type(self)

kind property #

This node's class — its name is the JSON "kind".

return_type property #

The CGType this node produces when executed.

uuid property #

This node's unique id (DAG identity / serialization key).

__setattr__(name, value) #

Absorb the path.field |= value rebind; reject any other mutation.

Source code in capturegraph-lib/capturegraph/procedures/procedure/methods/navigation.py
def __setattr__(
    self: Procedure[CGType],
    name: str,
    value: CacheProcedure[CGType],
) -> None:
    """Absorb the ``path.field |= value`` rebind; reject any other mutation."""
    absorb_cache_rebind(self, ("field", name), value, repr(name))