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]#

Level 0TLA⁺: CONSTANT c

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.

python
class Semaphore:
    capacity: Constant[int]

State[T] = Annotated[T, Role.STATE]#

Level 1TLA⁺: VARIABLE v

Declares a TLA⁺ VARIABLE kept by the implementation. Included in vars. A class-level default (x: State[int] = 0) contributes x = 0 to Init.

python
@dataclass
class Counter:
    x: State[int] = 0

Ghost[T] = Annotated[T, Role.GHOST]#

Level 1TLA⁺: VARIABLE g

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.

python
ledger: Ghost[tuple[int, ...]] = ()

Pure[T] = Annotated[T, Role.PURE]#

Level 1TLA⁺: Op == expr

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.

python
@property
def available(self) -> Pure[int]:
    return self.balance + self.credit_limit

Where(predicate: Callable[..., Any], description: str | None = None)#

Level 0 / 1TLA⁺: {x \in T : P(x)}

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.

ParameterTypeDescription
predicateCallable[[T], bool]Unary predicate narrowing values of T.
descriptionstr | NoneOptional human-readable name shown in diagnostics.
python
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.