Type Checkers
Pytifex runs four type checkers and compares their output to find disagreements. This page covers which checkers, how they get invoked, how their output gets parsed into “ok”/“error”, and how to add a new one.
The four checkers
| Checker | Version | Command | Project |
|---|---|---|---|
| mypy | 1.19.0 | mypy <file> |
mypy-lang.org |
| pyrefly | 0.44.2 | pyrefly check <file> |
github.com/facebook/pyrefly |
| zuban | 0.3.0 | zuban check <file> |
github.com/zubanls/zuban |
| ty | 0.0.1-alpha.32 | ty check <file> |
github.com/astral-sh/ty |
All four live in one dict in config.py:
CHECKERS = {
"mypy": ["mypy"],
"pyrefly": ["pyrefly", "check"],
"zuban": ["zuban", "check"],
"ty": ["ty", "check"],
}Each value is the argument list that gets handed to subprocess.run, with the file path appended.
How they get invoked
run_checkers.py walks every .py file in a generation directory and shells out to each checker:
def run_tool(command: list[str], filepath: str) -> str:
try:
full_cmd = command + [filepath]
result = subprocess.run(full_cmd, capture_output=True, text=True, check=False)
output = result.stdout
if result.stderr:
output += "\n[STDERR]\n" + result.stderr
return output.strip() if output.strip() else "Success (No Output)"
except FileNotFoundError:
return f"Error: Command '{command[0]}' not found in PATH."
except Exception as e:
return f"Execution Error: {str(e)}"A few things worth knowing:
check=False— a non-zero exit code never raises here. Most checkers exit non-zero whenever they find any type error, so the exit code by itself doesn’t tell you much.- stdout and stderr get merged into one string, with stderr appended after a
[STDERR]marker. - A missing checker binary doesn’t crash the run — you get a readable error string back instead.
The results collect into results.json:
for tool_name, command in CHECKERS.items():
output = run_tool(command, filepath)
file_result["outputs"][tool_name] = output
file_result["statuses"] = {}
for tool_name, output in file_result["outputs"].items():
file_result["statuses"][tool_name] = (
"error" if checker_reports_error(output, tool_name) else "ok"
)Parsing the output
Every checker formats its output differently, so there’s checker-specific parsing in _checker_reports_error(). That function lives in both comprehensive_eval.py and rederive_statuses.py — keep them in sync if you touch this.
mypy / zuban
Same format for both:
if checker in ("mypy", "zuban"):
if "success: no issues found" in output.lower():
return False
m = re.search(r"Found\s+(\d+)\s+errors?\s+in", output)
if m:
return int(m.group(1)) > 0
for line in output.splitlines():
if re.search(r":\s*error\b", line, re.IGNORECASE):
return True
return Falsepyrefly
Diagnostics start with ERROR. There’s a special case to filter out reveal_type() noise, which pyrefly reports as an “unknown-name” error even though it’s just a debugging call:
if checker == "pyrefly":
real_errors = 0
for line in output.splitlines():
s = line.strip()
if not s.startswith("ERROR"):
continue
if "unknown-name" in s.lower() and "reveal_type" in s:
continue
real_errors += 1
return real_errors > 0ty
Clean runs print All checks passed!. Errors are lines matching error[rule-name]: — warnings and info diagnostics don’t count:
if checker == "ty":
if "all checks passed" in output.lower():
return False
for line in output.splitlines():
if re.match(r"\s*error\[", line, re.IGNORECASE):
return True
return FalseAnything else
A generic fallback for an unrecognized checker name:
output_lower = output.lower()
return (
"error" in output_lower and
"0 error" not in output_lower and
"success" not in output_lower
)Re-deriving statuses after a parser change
If you fix the parsing logic, old results.json files still have statuses computed by the old version. There’s a script to recompute them — rederive_statuses.py. Run it as a module from the repo root, not as a bare script (it has relative imports):
python -m pytifex.rederive_statuses # dry run, reports mismatches only
python -m pytifex.rederive_statuses --apply # writes the corrected statusesOne caveat worth knowing: this script computes its ROOT as its own directory (src/pytifex/), but generated_examples/ actually lives at the repo root. So as written, the glob it builds (ROOT/generated_examples/*/results.json) won’t find your real output unless you run it with the working directory set to src/pytifex/ and a generated_examples symlink or copy sitting there too. If you hit this, it’s not you — it’s a path bug in the script, not something you did wrong.
Adding a new checker
Make sure it’s installed and on
PATH.Add it to
CHECKERSinconfig.py:CHECKERS = { "mypy": ["mypy"], "pyrefly": ["pyrefly", "check"], "zuban": ["zuban", "check"], "ty": ["ty", "check"], "pyright": ["pyright"], # new }Add parsing logic to
_checker_reports_error()— in bothcomprehensive_eval.pyandrederive_statuses.py:if checker == "pyright": # pyright prints "0 errors, 0 warnings, 0 informations" on success m = re.search(r"(\d+)\s+errors?", output) if m: return int(m.group(1)) > 0 return FalseRun the pipeline end-to-end to make sure it actually works:
uv run pytifex checkSanity-check your parser against a real
results.json. There’s a script for this too,check_checker_parsing.py— note it hardcodes a specific generation directory name inside it, so you’ll need to point it at one that exists before it’ll run:python -m pytifex.check_checker_parsing