Code, Contracts & Types · Page 1 of 6
Code as Its Own Specification
You do not have to write every transition twice. Give a method a real Python body and
Action() with no predicate, and the checker uses the Python body itself
as the transition.
Everything inside the body keeps its exact Python semantics: floor division (//),
negative indexing, short-circuiting and/or, and mutation of state
attributes. An assert statement inside an action body is verified across every
reachable state — a failing assert is reported as FAIL assertion,
and a raise on a reachable path fails too.
Try it: Remove
Requires(lambda s: s.x > 0), from
decrement and click Check. From the initial state
x = 0, decrement() immediately hits assert self.x >= 0
and fails with an assertion trace!