Why Temporal Typing?
Static type checkers like mypy and Pyright eliminate whole classes of bugs by verifying what values flow into and out of functions. Yet many of the hardest bugs in software are not value-shape bugs — they are state-evolution bugs:
- A bank account balance dropping below its credit limit after a sequence of withdrawals.
- A lock or queue starving a waiting process under contention.
- A circular ring buffer wrapping its head index off by one after a push/pop sequence.
- A transaction manager committing before every resource manager has prepared.
Solving Spec-to-Code Drift#
Formal specification languages like TLA⁺ excel at finding these bugs before production — but an external .tla file lives apart from the implementation. As the Python code evolves, the specification and the code silently drift apart.
Temporal Typing puts the specification directly on the Python class using standard typing.Annotated metadata:
- One source of truth: When an action has both an
Action(...)predicate and a Python body, a checker verifies that the body conforms to the predicate in every reachable state. - No separate language to learn first: Predicates and bodies use Python syntax with exact Python semantics (
//, 0-based indexing, comprehensions,frozenset,dict). - Incremental adoption: Start with a single
Invarianton a@dataclassusingAction(), then addRequires,Ensures,Ghoststate,Fairness, orRefines[A]as needed.
How It Compares#
| Tooling | Checks | Runtime Cost | Counterexamples |
|---|---|---|---|
typing + mypy / Pyright | Value shapes & interfaces | Zero | Static type errors |
| Unit & property tests | Sampled inputs & traces | Test-time | Random / hand-written cases |
| Standalone TLA⁺ + TLC | Exhaustive state machines & liveness | Zero (separate file) | TLA⁺ traces (can drift from code) |
| Temporal Typing + Tanny | Exhaustive state machines, liveness, contracts & code conformance | Zero (passive annotations) | Shortest Python-level traces |
The Core Design Rule#
Every rule in the Checker Specification follows one principle: a checker never guesses a domain, skips an unresolved import, or reports PASS for a construct it cannot give its exact Python meaning to. If something cannot be checked, it is an explicit ERROR.