pyqt_reactive.services.scope_token_service

Helpers for generating stable scope tokens for ObjectState hierarchy nodes.

Used to avoid cross-window collisions when multiple child editors share the same scope prefix (e.g., steps, nested functions).

Classes

ScopeTokenGenerator(prefix[, attr_name])

Generate unique, human-readable scope tokens with an optional attribute store.

ScopeTokenObjectStore()

Persist scope tokens without exposing attribute probing to callers.

ScopeTokenService()

Registry of ScopeTokenGenerators keyed by (parent_scope, prefix).

ScopeTokenTarget()

Nominal role for objects that can participate in scope-token identity.

class pyqt_reactive.services.scope_token_service.ScopeTokenTarget[source]

Nominal role for objects that can participate in scope-token identity.

class pyqt_reactive.services.scope_token_service.ScopeTokenObjectStore[source]

Persist scope tokens without exposing attribute probing to callers.

classmethod read(obj: ScopeTokenTarget, attr_name: str) str | None[source]
classmethod write(obj: ScopeTokenTarget, attr_name: str, token: str) None[source]
class pyqt_reactive.services.scope_token_service.ScopeTokenGenerator(prefix: str, attr_name: str | None = None)[source]

Generate unique, human-readable scope tokens with an optional attribute store.

  • If attr_name is provided and the target object exposes an instance mapping, tokens are persisted there (e.g., FunctionStep._scope_token).

  • Tracks seen tokens to avoid collisions when objects already carry tokens (e.g., after deserialization).

__init__(prefix: str, attr_name: str | None = None)[source]
seed_from_tokens(tokens: Iterable[str] | None) None[source]

Prime the generator with existing tokens (keeps counter ahead of them).

seed_from_objects(objects: Iterable[ScopeTokenTarget] | None) None[source]

Seed from objects that may already carry tokens on attr_name.

ensure(obj: ScopeTokenTarget | None = None) str[source]

Return an existing token on obj or generate a new one.

transfer(source: ScopeTokenTarget, target: ScopeTokenTarget) str[source]

Copy source token to target (or generate a new one for target).

normalize(objects: Iterable[ScopeTokenTarget] | None) None[source]

Ensure every object in a list has a token.

static existing_token(obj: ScopeTokenTarget, attr_name: str) str | None[source]

Return an existing token from the configured storage attribute.

class pyqt_reactive.services.scope_token_service.ScopeTokenService[source]

Registry of ScopeTokenGenerators keyed by (parent_scope, prefix).

Token assigned on creation, stable across reordering. Prefix derived from object type for readability.

Usage:

ScopeTokenService.build_scope_id(plate_path, step) # → “plate::step_0” ScopeTokenService.build_scope_id(step_scope, func) # → “plate::step_0::func_0”

classmethod get_generator(parent_scope, prefix: str) ScopeTokenGenerator[source]
classmethod ensure_token(parent_scope, obj: ScopeTokenTarget) str[source]
classmethod transfer_token(parent_scope, source: ScopeTokenTarget, target: ScopeTokenTarget) str[source]

Transfer source object’s scope token to a replacement target.

classmethod adopt_token(parent_scope, obj: ScopeTokenTarget, token: str) str[source]

Assign a known scope token to an object through the token authority.

classmethod object_token(obj: ScopeTokenTarget) str | None[source]

Return an object’s existing scope token without creating one.

classmethod same_object_token(left: ScopeTokenTarget, right: ScopeTokenTarget) bool[source]

Return whether two objects carry the same existing scope token.

classmethod build_scope_id(parent_scope, obj: ScopeTokenTarget) str[source]
classmethod seed_from_objects(parent_scope, objects: Sequence[ScopeTokenTarget]) None[source]

Seed generators from existing objects (preserves their tokens).

classmethod clear_scope(parent_scope) None[source]

Clear all generators for a parent scope (and nested children).