Skip to content

mypy -> ty - #72

Merged
tony merged 3 commits into
masterfrom
ty
Nov 29, 2026
Merged

tony merged 3 commits into
masterfrom
ty

Conversation

@tony

@tony tony commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Closes #71.

CI, make ty, watch mode and the editor now check with ty 0.0.113. The gate still covers the package, tests, root fixture and Sphinx configuration. Ruff enforces parameter and return annotations. The Python sources and public CLI are unchanged. Checker configuration · CI invocation

Benchmark observations

Mean wall-clock time ± sample standard deviation across eight fresh processes per cell, using Hyperfine 1.20.0 on Linux x86_64, CPython 3.15.0 and uv 0.13.10. Both checkers targeted Python 3.11 and read the same files and installed packages. All 32 timed commands exited 0. Both checkers reported zero diagnostics in untimed empty-cache and repeat runs.

Cold samples started with an empty checker cache. The OS filesystem cache remained available for every sample. mypy produced a persistent cache. The ty CLI wrote no files to its isolated cache directory, so its warm row measures repeated fresh processes. Installation and environment setup were outside the timed commands. Trunk mypy settings · Trunk lock · Candidate lock

The common file manifest consists of conftest.py, docs/conf.py, package metadata, the CLI and the CLI tests.

Benchmark commands and pinned configurations · File manifest · All 32 samples

Verification

  • Locked dependency sync, Ruff lint and format, and the repository-wide ty check passed.
  • A temporary invalid assignment in each of the five files produced five diagnostics. The clean files passed afterward.
  • All 11 tests passed, and the Sphinx documentation built successfully.
  • The configured editor command completed a language-server initialize and shutdown exchange.

The release note for #72 records the changes for this release.

Type-checker benchmark

On g’s five tracked Python files, ty averaged 41.9 ms with an empty checker cache and 43.0 ms on repeat invocations. The mypy baseline uses g’s pre-migration strict configuration, mypy 2.4.1, and its locked stub packages. The five Python files are byte-identical across the two commits. Trunk mypy settings · Migration ty settings · Trunk lock · Migration lock

Cache state mypy 2.4.1 ty 0.0.113 mypy / ty
Empty checker cache 2262.0 ± 112.5 ms 41.9 ± 2.9 ms 54.02×
Repeat after two warmups 153.9 ± 9.5 ms 43.0 ± 5.8 ms 3.58×

Each cell gives the mean wall time and sample standard deviation across eight fresh CLI processes. All 32 measured invocations exited 0. Both checkers reported zero errors and warnings on separate empty-cache and repeat checks. Both targeted Python 3.11 and used the same CPython 3.15.0 environment, including types-docutils 0.23.0.20261122 and types-pygments 2.21.0.20261122.

Hyperfine 1.20.0 timed the installed checker binaries on Linux x86-64 (Core i7-12700H). The cold series cleared mypy’s module cache before each run. The warm series reused it after two untimed warmups. ty check exposed no persistent cache option and wrote no files under its isolated cache directory. Its repeat series timed fresh processes after two untimed runs. The OS page cache stayed warm. Installation, diagnostics capture, Ruff and pytest ran outside the timed commands.

Wall time for each sample
Command Wall-clock samples (ms)
mypy, cold 2202.29, 2101.81, 2200.27, 2223.95, 2215.18, 2331.49, 2371.96, 2448.94
ty, cold 42.80, 40.34, 39.82, 44.12, 42.41, 40.24, 47.30, 37.96
mypy, warm 157.07, 148.48, 144.82, 173.79, 155.67, 157.25, 144.77, 149.59
ty, warm 46.98, 50.74, 50.42, 43.58, 40.20, 38.41, 37.24, 36.26

File manifest

Both checkers received these five paths as explicit arguments, matching the tracked Python files under trunk CI’s mypy . invocation. The two snapshots contain no tracked .pyi files.

  • conftest.py
  • docs/conf.py
  • src/g/__about__.py
  • src/g/__init__.py
  • tests/test_cli.py

Reproduce

Run from a clone containing both commits with Bash, uv 0.13.10, Hyperfine 1.20.0 and jq. The script reads the two snapshots into a temporary directory and prints the directory containing the four raw timing files.

$ bash <<'SH'
set -euo pipefail
base=ee7fdf72a88db0ae72d0dab461d7abf35a58dc38
candidate=eed6ad7e1c20710751f821abf7aac96fd74d464e
work=$(mktemp -d)
results=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
mkdir "$work/base" "$work/candidate"
for file in pyproject.toml uv.lock; do
  git show "$base:$file" > "$work/base/$file"
done
git archive -o "$work/source.tar" "$candidate"
tar -xf "$work/source.tar" -C "$work/candidate"
unset PYTHONHOME PYTHONPATH VIRTUAL_ENV
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.15.0)
uv sync "${opts[@]}" --project "$work/candidate"
uv sync "${opts[@]}" \
  --project "$work/base" \
  --inexact \
  --no-install-project
export VIRTUAL_ENV="$work/venv" PATH="$work/venv/bin:$PATH"
export XDG_CACHE_HOME="$work/ty-cache" XDG_CONFIG_HOME="$work/config" NO_COLOR=1
cd "$work/candidate"
files=(conftest.py docs/conf.py src/g/__about__.py src/g/__init__.py tests/test_cli.py)
status=0
for state in diagnostics cold warm; do
  for tool in mypy ty; do
    if [[ $tool == mypy ]]; then
      cache="$work/mypy-cache"
      cmd=(mypy --config-file "$work/base/pyproject.toml" --python-executable "$work/venv/bin/python" --cache-dir "$cache")
    else
      cache="$XDG_CACHE_HOME"
      cmd=(ty check --python "$work/venv/bin/python")
    fi
    if [[ $state == diagnostics ]]; then
      for pass in 1 2; do "${cmd[@]}" "${files[@]}" || status=1; done
      continue
    fi
    if [[ $state == cold ]]; then
      printf -v clear_cache '%q ' rm -rf "$cache"
      controls=(--prepare "$clear_cache")
    else
      controls=(--warmup 2)
    fi
    printf -v command '%q ' "${cmd[@]}" "${files[@]}"
    json="$results/$tool-$state.json"
    hyperfine --shell=none \
      --runs 8 \
      --ignore-failure \
      --command-name "$tool-$state" \
      --export-json "$json" \
      "${controls[@]}" "$command"
    jq -e '.results[].exit_codes | length == 8 and all(. == 0)' "$json" || status=1
  done
done
printf 'Raw measurements: %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

Checks on 317ec6c0821d

Passed — CodeQL · Analyze (python) · Analyze (actions) · build (3.15).

Skipped — release · release · build.

why: Contributors and CI need the same type checks across the package,
tests, pytest fixtures, and Sphinx configuration.

what:
- Run ty in CI, Make, and the editor using the locked dev dependency.
- Keep checking generic arguments and dynamic returns with ty and
  require parameter and return annotations with Ruff.
- Exempt only ty from the release cooldown for the checker migration.
@codecov-commenter

codecov-commenter commented Nov 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.40%. Comparing base (ee7fdf7) to head (317ec6c).

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #72   +/-   ##
=======================================
  Coverage   97.40%   97.40%           
=======================================
  Files           5        5           
  Lines         154      154           
=======================================
  Hits          150      150           
  Misses          4        4           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

tony added a commit that referenced this pull request Nov 29, 2026
why: Contributors need the supported checker and its scope in the release notes.
what:
- Summarize the migration and link its pull request.
@tony tony changed the title ci(typing) Check the full project with ty mypy -> ty Nov 29, 2026
tony added 2 commits November 29, 2026 13:15
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.
why: Contributors need the supported checker and its scope in the release notes.
what:
- Summarize the migration and link its pull request.
@tony
tony merged commit 7af31c8 into master Nov 29, 2026
7 checks passed
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.

Migrate the project type check from mypy to ty

2 participants