Evaluation System
Finding a disagreement is only half the job — once mypy says “ok” and pyrefly says “error” on the same code, something has to decide which one was actually right. This page covers the two-phase evaluation that does that.
(Note on naming: the code itself still calls these “tiers” internally — function names like run_tier1, the tier2_bugs list, and the "tier": 2 field in the JSON output below are all literal. This doc calls them Phase 1 / Phase 2 going forward; the rename in code hasn’t landed yet.)
The rule it’s built on
Only runtime evidence counts. No heuristics, no PEP pattern matching, no LLM judgement in the verdict itself — a verdict only gets issued when there’s an actual crash or an actual successful execution to point to.
- Phase 1 proves false negatives. A runtime crash is concrete proof a type error exists — any checker that said “ok” was wrong.
- Phase 2 proves both directions. Hypothesis generates inputs that match the declared types (verified at the call boundary by beartype), then actually calls the function. A crash proves a false negative; a clean run proves a false positive.
| Case | Proves |
|---|---|
| Phase 1 crash | checker that said “ok” is wrong (false negative), confidence 0.95 |
| Phase 2 crash with type-conformant inputs | same, via fuzzing, confidence 0.85 |
| Phase 2 success witness | checker that said “error” is wrong (false positive), confidence 0.90 |
| neither | UNCERTAIN |
Phase 1 — runtime crash detection
Runs the code directly and catches the exceptions that actually signal a type error:
TYPE_ERROR_EXCEPTIONS = (TypeError, KeyError, AttributeError)If it crashes, any checker that said “ok” has a proven false negative. If it doesn’t, Phase 1 has nothing to say and the result falls through to Phase 2.
It doesn’t just look at the top-level exception — it walks the whole traceback and follows exception chains (__cause__/__context__) to find the actual root cause, not just wherever the error happened to surface:
def _collect_chained_exceptions(exc):
chain = []
current = exc
while current is not None:
chain.append(current)
current = current.__cause__ or current.__context__
chain.reverse() # root cause first
return chainIt also re-executes every try/except body on its own, in isolation, specifically to catch errors that the code’s own exception handling would otherwise swallow silently.
Phase 2 — Hypothesis property testing
Parse the AST to find every user-defined function and method.
Execute the source once to get a real, callable namespace.
Look up each callable’s signature and type hints with
inspectandtyping.get_type_hints().Build a Hypothesis strategy per parameter type:
int -> st.integers() list[int] -> st.lists(st.integers()) Optional[str] -> st.none() | st.text() # custom classes get constructed recursively from their own __init__ hintsWrap the call with
@beartype. If a generated input somehow doesn’t conform to its declared type, beartype raises before the real function body runs, and that call gets skipped rather than counted as evidence either way.Run
@giventests and watch what happens.
A crash on type-conformant input (Phase 2a) is the same kind of false-negative proof as Phase 1, just found through fuzzing instead of one fixed example. A clean run (Phase 2b) gets recorded as a SuccessWitness:
@dataclass
class SuccessWitness:
call_text: str # e.g. "multiply(...)"
calls_succeeded: int # number of successful Hypothesis calls
beartype_enforced: bool # True when beartype confirmed input conformanceA success witness is concrete proof the code is well-typed for at least one real call. Any checker that reported “error” on it has a proven false positive.
One more source feeds Phase 2’s bug list: targeted_tests.py. It’s not Hypothesis-based — it’s hand-written probes (empty tuples, NewType cross-contamination, decorator signature erasure, Protocol conformance, classmethod inheritance, and literally replaying the file’s own if __name__ == "__main__" block) that catch bugs Hypothesis’s generic strategies tend to miss. Its findings get merged into the same list (tier2_bugs in the code) before a verdict gets decided.
Running it
uv run --extra dev pytifex # generate + evaluate
uv run --extra dev pytifex eval # evaluate existing results onlyOutput goes to evaluation_comprehensive.json. The field is still called "tier" in the JSON — same naming gap as above:
{
"method": "two_tier_objective",
"summary": {
"mypy": {"correct": 8, "incorrect": 4, "uncertain": 3},
"pyrefly": {"correct": 6, "incorrect": 5, "uncertain": 4}
},
"results": [
{
"filename": "protocol-defaults-1.py",
"tier1_bugs": [],
"tier2_bugs": [],
"tier2_witnesses": [
{"call": "render(...)", "successes": 30, "beartype_enforced": true}
],
"verdicts": {
"mypy": {"verdict": "INCORRECT", "tier": 2, "confidence": 0.9,
"reason": "False positive: reported error on code that executed successfully with type-conformant inputs (30 successful call(s), beartype-enforced)"},
"pyrefly": {"verdict": "CORRECT", "tier": 2, "confidence": 0.9,
"reason": "Correctly accepted code that executed successfully with type-conformant inputs (30 successful call(s), beartype-enforced)"}
}
}
]
}| Verdict | Meaning |
|---|---|
CORRECT |
caught every real issue, or correctly reported no issues |
INCORRECT |
missed a real bug, or flagged code that’s actually fine |
UNCERTAIN |
neither a crash nor a success witness — no runtime evidence either way |
UNCERTAIN cases get escalated to an LLM judge as a last resort, which has to cite a specific PEP section for its answer rather than just guessing — but that only kicks in once both phases come back empty-handed. It’s not part of the core verdict logic above.
If you want to see what’s going on behind a particular verdict, every generated test (every Phase 1 crash reproduction, every Phase 2 property test, every targeted probe) gets saved as an actual .py file under generated_examples/<run>/tests/ — nothing here is a black box.
See Architecture for the additional evaluation modules that exist in the codebase but aren’t part of this verdict path.