Roles & Type Annotations
Field and return-type role markers from temporal_typing. Every role is an ordinary typing.Annotated alias.
Constant[T] = Annotated[T, Role.CONSTANT]#
Declares a TLA⁺ CONSTANT on a specification class. Fixed by Model.constants (or a class-level default) and identical in every state. Assigning to a constant inside an action body is bad-write.
class Semaphore:
capacity: Constant[int]State[T] = Annotated[T, Role.STATE]#
Declares a TLA⁺ VARIABLE kept by the implementation. Included in vars. A class-level default (x: State[int] = 0) contributes x = 0 to Init.
@dataclass
class Counter:
x: State[int] = 0Ghost[T] = Annotated[T, Role.GHOST]#
Declares a specification-only TLA⁺ VARIABLE (such as a history ledger or prophecy variable). Included in vars. Method bodies do not need to update ghost variables; the checker derives their next value from the Action predicate.
ledger: Ghost[tuple[int, ...]] = ()Pure[T] = Annotated[T, Role.PURE]#
Marks a method, @property, or function return type as a side-effect-free operator. Predicates may read Pure operators (e.g. s.available). Mutating state inside a Pure body is rejected as bad-write.
@property
def available(self) -> Pure[int]:
return self.balance + self.credit_limitWhere(predicate: Callable[..., Any], description: str | None = None)#
Refines a type as a set comprehension {x ∈ T : predicate(x)} inside Annotated[T, Where(...)]. Meaning depends on position: assumption on Constant, invariant on State/Ghost, guard on parameters, obligation on return types.
| Parameter | Type | Description |
|---|---|---|
predicate | Callable[[T], bool] | Unary predicate narrowing values of T. |
description | str | None | Optional human-readable name shown in diagnostics. |
Positive = Annotated[int, Where(lambda x: x > 0, "positive")]class Role(Enum)#
Metadata enum backing Constant, State, Ghost, and Pure: members are Role.CONSTANT, Role.STATE, Role.GHOST, and Role.PURE.