Skip to content

upgrade ty - #352

Merged
tony merged 3 commits into
mainfrom
ty
Nov 30, 2026
Merged

tony merged 3 commits into
mainfrom
ty

Conversation

@tony

@tony tony commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Closes #351.

The documentation site’s Python type check now includes the API-model tests. Its previous configuration covered the site scripts and exporter, leaving both Python test files outside the gate. The expanded check found four diagnostics in the Haskell exporter tests. They now require an importable exporter and a matching source link before using either value.

CI runs the existing Python toolchain on the supported 3.12 floor and the project’s 3.14 development interpreter. Both local suites passed 35 tests and 46 subtests. Ruff lint and formatting passed on both. On each target, a deliberately invalid assignment was detected in every one of the 12 tracked Python files. The existing lint configuration has no function-annotation requirement. The checker lock changed from ty 0.0.88 to 0.0.113 and retains the repository’s three-day cooldown for other packages.

Type-checker benchmark

The benchmark uses a synthetic mypy configuration. Its timings apply to the supplied benchmark configuration. Both tools checked the same 12 candidate files with Python 3.12.13. Both targeted Python 3.12. The two source snapshots differ in 1 of those files. The two series do not establish a clean-check speed ratio. Ty passed. Strict synthetic mypy reported 280 errors on the candidate and 284 on trunk. Mypy settings · Ty settings · Candidate lock · Baseline lock

Cache state mypy 2.4.1 ty 0.0.113
Empty checker cache 2744.2 ± 238.7 ms 75.9 ± 4.0 ms
Repeat after two warmups 136.1 ± 4.6 ms 68.3 ± 3.6 ms

The table gives mean wall time and sample standard deviation across 8 fresh CLI processes per cell. mypy 2.4.1 exited 1 (16/16). ty 0.0.113 exited 0 (16/16). hyperfine 1.20.0 timed the installed checker executables on Linux x86_64. Mypy used no configured plugins. Each sample launches one checker process over the same source manifest.

Cold runs cleared the checker cache before each sample. Repeat runs followed two untimed warmups. Mypy reused its module cache. Ty wrote no files under its isolated cache root, so its repeat timings measure another fresh process. The OS page cache stayed warm. Setup and diagnostics ran outside the timed commands.

Synthetic mypy configuration

[tool.mypy]
strict = true
python_version = "3.12"

Diagnostics

Check Exit Errors Warnings
ty-trunk 0 0 0
mypy-base-candidate-deps 1 284 0
ty-candidate-project 0 0 0
mypy-empty 1 280 0
mypy-repeat 1 280 0
ty-empty 0 0 0
ty-repeat 0 0 0

mypy-base-candidate-deps reported Found 284 errors in 8 files (checked 12 source files).

The examples show 7 distinct checker/rule combinations. The totals include all reported locations.

Samples

Checker State Exit codes, in order Wall times (ms)
mypy cold 1, 1, 1, 1, 1, 1, 1, 1 2952.56, 2928.39, 2759.96, 2992.34, 2572.14, 2900.38, 2433.00, 2414.48
ty cold 0, 0, 0, 0, 0, 0, 0, 0 75.16, 72.13, 76.51, 74.57, 72.54, 81.26, 82.44, 72.41
mypy warm 1, 1, 1, 1, 1, 1, 1, 1 133.89, 135.54, 130.62, 143.79, 141.80, 135.65, 131.58, 136.08
ty warm 0, 0, 0, 0, 0, 0, 0, 0 65.66, 66.19, 63.94, 71.54, 70.27, 70.24, 64.73, 73.74

File manifest

  • packages/api-model/scripts/export-haskell.py
  • packages/api-model/test/test_haskell_export.py
  • packages/api-model/test/test_python_scope.py
  • scripts/check-doxygen.py
  • scripts/check-example-prose.py
  • scripts/check-go-prose.py
  • scripts/check-inventories.py
  • scripts/check-workspace-prose.py
  • scripts/example_tmux_sandbox.py
  • scripts/gen-tmux-layout-fixture.py
  • scripts/read-elixir-toolchain.py
  • scripts/read-haskell-toolchain.py

Reproduce

Run from a clone containing both measured revisions with bash, uv 0.12.0, hyperfine 1.20.0 and the utilities used below. The reproduction exits 1 if a historical control or synthetic checker returns nonzero.

$ bash <<'SH'
set -euo pipefail
base=cf67b78fb6a22601a74d22ea369199dcbbfd8fd1
candidate=58f595662e3be79524d0088ddf916f970daa8a98
project=.
work=$(mktemp -d)
results=$(mktemp -d)
export work results project
trap 'rm -rf "$work"' EXIT
for side in base candidate; do
  mkdir "$work/$side"
  git archive -o "$work/source.tar" "${!side}"
  tar -xf "$work/source.tar" -C "$work/$side"

done
unset VIRTUAL_ENV PYTHONPATH PYTHONHOME UV_PROJECT UV_WORKING_DIRECTORY
for key in $(compgen -e | awk '/^(MYPY|TY_)/'); do unset "$key"; done
export UV_PROJECT_ENVIRONMENT="$work/venv"
opts=(--frozen --dev --all-extras --python 3.12.13)
uv sync "${opts[@]}" --project "$work/base/$project"
export VIRTUAL_ENV="$work/venv" NO_COLOR=1
export XDG_CACHE_HOME="$work/xdg-cache" XDG_CONFIG_HOME="$work/xdg-config"
status=0
(cd "$work/base" && "$VIRTUAL_ENV/bin/ty" check --project "$project" --python "$VIRTUAL_ENV/bin/python" --output-format concise) > "$results/ty-trunk.txt" 2>&1 || status=1
uv sync "${opts[@]}" --project "$work/candidate/$project"
uv pip freeze --python "$VIRTUAL_ENV/bin/python" > "$results/candidate-constraints.txt"
cat > "$results/overlay.txt" <<'PINS'
ast-serialize==0.13.1
librt==0.17.0
mypy==2.4.1
mypy-extensions==1.2.0
pathspec==1.1.1
typing-extensions==4.16.0
PINS
uv pip install --python "$VIRTUAL_ENV/bin/python" -c "$results/candidate-constraints.txt" -r "$results/overlay.txt"
uv pip check --python "$VIRTUAL_ENV/bin/python"
cat > "$results/synthetic-mypy.toml" <<'TOML'
[tool.mypy]
strict = true
python_version = "3.12"
TOML
cat > "$work/mypy-base" <<'CHECK'
#!/bin/sh
status=0
"$VIRTUAL_ENV/bin/mypy" --python-executable "$VIRTUAL_ENV/bin/python" --config-file "$results/synthetic-mypy.toml" --cache-dir "$work/trunk-cache/group-1" "$@" -- packages/api-model/scripts/export-haskell.py packages/api-model/test/test_haskell_export.py packages/api-model/test/test_python_scope.py scripts/check-doxygen.py scripts/check-example-prose.py scripts/check-go-prose.py scripts/check-inventories.py scripts/check-workspace-prose.py scripts/example_tmux_sandbox.py scripts/gen-tmux-layout-fixture.py scripts/read-elixir-toolchain.py scripts/read-haskell-toolchain.py || { code=$?; [ "$code" -le "$status" ] || status=$code; }
exit "$status"
CHECK
chmod +x "$work/mypy-base"
cat > "$work/mypy" <<'CHECK'
#!/bin/sh
status=0
"$VIRTUAL_ENV/bin/mypy" --python-executable "$VIRTUAL_ENV/bin/python" --config-file "$results/synthetic-mypy.toml" --cache-dir "$work/mypy-cache/group-1" "$@" -- packages/api-model/scripts/export-haskell.py packages/api-model/test/test_haskell_export.py packages/api-model/test/test_python_scope.py scripts/check-doxygen.py scripts/check-example-prose.py scripts/check-go-prose.py scripts/check-inventories.py scripts/check-workspace-prose.py scripts/example_tmux_sandbox.py scripts/gen-tmux-layout-fixture.py scripts/read-elixir-toolchain.py scripts/read-haskell-toolchain.py || { code=$?; [ "$code" -le "$status" ] || status=$code; }
exit "$status"
CHECK
chmod +x "$work/mypy"
cat > "$work/ty" <<'CHECK'
#!/bin/sh
status=0
"$VIRTUAL_ENV/bin/ty" check --project "$work/candidate/$project" --python "$VIRTUAL_ENV/bin/python" --python-version 3.12 --error-on-warning "$@" -- packages/api-model/scripts/export-haskell.py packages/api-model/test/test_haskell_export.py packages/api-model/test/test_python_scope.py scripts/check-doxygen.py scripts/check-example-prose.py scripts/check-go-prose.py scripts/check-inventories.py scripts/check-workspace-prose.py scripts/example_tmux_sandbox.py scripts/gen-tmux-layout-fixture.py scripts/read-elixir-toolchain.py scripts/read-haskell-toolchain.py || { code=$?; [ "$code" -le "$status" ] || status=$code; }
exit "$status"
CHECK
chmod +x "$work/ty"
(cd "$work/base" && "$work/mypy-base") > "$results/mypy-base-candidate-deps.txt" 2>&1 || status=1
cd "$work/candidate"
"$VIRTUAL_ENV/bin/ty" check --project "$project" --python "$VIRTUAL_ENV/bin/python" --python-version 3.12 --error-on-warning --output-format concise > "$results/ty-candidate-project.txt" 2>&1 || status=1

for state in diagnostics cold warm; do
  for checker in mypy ty; do
    cache="$work/mypy-cache"
    [[ $checker == mypy ]] || cache="$XDG_CACHE_HOME"
    if [[ $state == diagnostics ]]; then
      rm -rf "$cache"
      diag=()
      [[ $checker == mypy ]] || diag=(--output-format concise)
      for pass in empty repeat; do
        "$work/$checker" "${diag[@]}" > "$results/$checker-$pass.txt" 2>&1 || status=1
      done
      continue
    fi
    controls=()
    if [[ $state == cold ]]; then
      printf -v clear '%q ' rm -rf "$cache"
      controls=(--prepare "$clear")
    else
      for pass in 1 2; do "$work/$checker" >/dev/null 2>&1 || status=1; done
    fi
    json="$results/$checker-$state.json"
    hyperfine --shell=none \
      --runs 8 \
      --ignore-failure \
      --command-name "$checker-$state" \
      --export-json "$json" \
      "${controls[@]}" "$work/$checker"
    jq -e '.results[].exit_codes | length == 8 and all(. == 0)' "$json" || status=1
  done
done
printf 'Raw evidence: %s\n' "$results"
exit "$status"
SH

The Python typing policy describes how to check a proposed signature against downstream callers and when an open input type is appropriate.

Hosted checks

The Python 3.12 and 3.14 jobs passed their type checks and tooling tests. Both F# extraction jobs passed. The full documentation integration suite and the preview publishing dry run passed. The preview publication was still syncing the audited site at the time of merge review. Python 3.12 · Python 3.14 · Full integration · Preview dry run · Preview publication · Checks on efaffbe2a0c9

tony added 3 commits November 29, 2026 11:44
why: The previous source list left the exporter tests outside the type
gate. Those tests run the Python exporter used to assemble the site.

what:
- Pin ty 0.0.113 with its own package cooldown exception.
- Check the maintained Python tests alongside scripts and exporter code.
- Run the type and test commands on Python 3.12 and 3.14 in CI.
why: The fixture expects a loadable exporter module and a source line
link. A missing loader or regex match should identify the failed setup.

what:
- Check the module specification and loader before executing the fixture.
- Assert a native line match before reading the matched anchor.
why: Contributors need a consistent way to resolve typing ambiguities while preserving the contract callers rely on.
what:
- Describe the limited uses of object and Any at input boundaries.
- Check precise signatures against supported callers, misuse and downstream inference.
@tony
tony merged commit eda3789 into main Nov 30, 2026
7 checks passed
@tony
tony deployed to docs-preview-cleanup November 30, 2026 00:48 — with GitHub Actions Active

This branch was successfully deployed

1 active and 1 inactive deployments
docs-preview-cleanup — efaffbe2 Deployed Nov 30, 2026 by tony via cleanup #278
docs-preview — efaffbe2 Deployed Nov 30, 2026 by tony via publish-preview / publish #1569
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make the existing ty configuration a verified Python check

1 participant