Specifications & State · Page 1 of 6
A Specification Is a Class
A specification is a Python class — a Protocol, a @dataclass,
a plain class, or a Generic.
- State variables are fields annotated with
State[T]. - Class clauses are named keyword arguments to
@spec(...), each taking a predicatelambda s: ...wheresis the state. - Actions are methods whose return annotation carries
Action(...).
When a method body is ..., the method is abstract: its Action
predicate is the transition. Because @spec does not alter the class's
type, Counter remains a normal Protocol that any matching Python class
satisfies.
Try it: Change the guard in
increment from s.x < 10
to s.x <= 10 and click Check. Watch the checker reach
x = 11 and fail bounded.