Skip to content

mypy -> ty - #164

Merged
tony merged 6 commits into
mainfrom
ty
Nov 29, 2026
Merged

tony merged 6 commits into
mainfrom
ty

Conversation

@tony

@tony tony commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Type coverage

The project and its hidden build helpers now run ty on Python 3.11 and 3.15. The MCP tools keep their existing libtmux dependency and dispatch commands on the original server, session, window or pane. Functions that only execute commands accept libtmux’s public CmdMixin receiver. The remaining mixed-use calls pass string arguments through one helper that invokes the same bound method.

Command dispatch

At the first draft, ty reported 29 argument-count errors. The environment mixin on libtmux 0.62.0 declares two positional arguments, even though the concrete method accepts a command followed by arbitrary tmux arguments. All nine published releases from 0.62.0 through 0.69.0 have that declaration. Version 0.70.0 corrected it, but substituting that release failed 30 consumer runtime tests on each supported endpoint. The shared command mixin was already present in the locked 0.62.0 release. Original mixins · Upstream signature change

On an isolated tmux socket, direct and typed calls produced identical command arguments, stdout, stderr and exit codes for all four concrete receivers and a server subclass overriding cmd. A format query succeeded and an invalid tmux command returned exit 1 with the same error. Passing a list where one string argument is required reached the checker as an invalid argument.

Verification

  • Python 3.11.15 and 3.15.1 each passed 953 runtime tests and 16 build-helper tests, with six runtime skips and four passing snapshots. Both endpoints passed ty, Ruff and formatting. The unchanged 3.11 runtime control passed 952 tests and failed one test that assumed a default socket directory. The candidate reads the owned fixture directory before changing the discovery environment.
  • Assignment and missing-signature controls reached all 84 files on both endpoints. The Sphinx HTML build completed with 30 warnings.

The completed workflow on the measured source passed seven tmux runtime builds and both Python type checks. Hosted checks

Closes #163.

Type-checker benchmark

The mypy baseline uses the project’s pre-migration settings and dependency lock. Both tools checked the same 84 candidate files with Python 3.11.15. Both targeted Python 3.11. The two source snapshots differ in 23 of those files. Mypy settings · Ty settings · Candidate lock · Baseline lock

Cache state mypy 2.4.1 ty 0.0.113 mypy / ty
Empty checker cache 9047.3 ± 1099.2 ms 202.9 ± 19.8 ms 44.58×
Repeat after two warmups 316.0 ± 23.6 ms 278.9 ± 50.5 ms 1.13×

The table gives mean wall time and sample standard deviation across 8 fresh CLI processes per cell. mypy 2.4.1 exited 0 (16/16). ty 0.0.113 exited 0 (16/16). hyperfine 1.20.0 timed the installed checker executables on Linux x86_64. Stub packages in the shared environment include types-docutils 0.23.0.20261122, types-regex 2026.11.19.20261122. Mypy used no configured plugins. The historical config enabled ignore_missing_imports for docutils, docutils.*. Both commands used the locked libtmux 0.62.0 release and checked the same 84 candidate files. The original mypy native commands checked 72 ordinary files and two hidden build helpers. Passing all 84 paths explicitly includes the documentation sources on both snapshots.

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.

Diagnostics

Check Exit Errors Warnings
mypy-trunk 0 0 0
mypy-trunk-native-1 0 0 0
mypy-trunk-native-2 0 0 0
mypy-empty 0 0 0
mypy-repeat 0 0 0
ty-empty 0 0 0
ty-repeat 0 0 0

mypy-trunk reported Success: no issues found in 84 source files. mypy-trunk-native-1 reported Success: no issues found in 72 source files. mypy-trunk-native-2 reported Success: no issues found in 2 source files.

Samples

Checker State Exit codes, in order Wall times (ms)
mypy cold 0, 0, 0, 0, 0, 0, 0, 0 8190.17, 7977.37, 9111.73, 8410.75, 8892.40, 11456.60, 9563.64, 8775.35
ty cold 0, 0, 0, 0, 0, 0, 0, 0 189.64, 177.20, 220.15, 233.31, 214.63, 211.88, 184.23, 192.42
mypy warm 0, 0, 0, 0, 0, 0, 0, 0 324.56, 290.49, 334.99, 323.54, 356.76, 287.54, 309.97, 300.07
ty warm 0, 0, 0, 0, 0, 0, 0, 0 209.14, 325.66, 329.13, 344.89, 249.51, 272.55, 276.59, 224.09

File manifest

  • .github/scripts/test_tmux_build.py
  • .github/scripts/tmux_build.py
  • conftest.py
  • docs/__init__.py
  • docs/_ext/__init__.py
  • docs/_ext/widgets/__init__.py
  • docs/_ext/widgets/_assets.py
  • docs/_ext/widgets/_base.py
  • docs/_ext/widgets/_directive.py
  • docs/_ext/widgets/_discovery.py
  • docs/_ext/widgets/_prehydrate.py
  • docs/_ext/widgets/mcp_install.py
  • docs/conf.py
  • scripts/mcp_swap.py
  • src/libtmux_mcp/__about__.py
  • src/libtmux_mcp/__init__.py
  • src/libtmux_mcp/__main__.py
  • src/libtmux_mcp/_history.py
  • src/libtmux_mcp/_tmux_proc.py
  • src/libtmux_mcp/_utils.py
  • src/libtmux_mcp/_wait_policy.py
  • src/libtmux_mcp/middleware.py
  • src/libtmux_mcp/models.py
  • src/libtmux_mcp/prompts/__init__.py
  • src/libtmux_mcp/prompts/recipes.py
  • src/libtmux_mcp/resources/__init__.py
  • src/libtmux_mcp/resources/hierarchy.py
  • src/libtmux_mcp/resources/viewer.py
  • src/libtmux_mcp/server.py
  • src/libtmux_mcp/tools/__init__.py
  • src/libtmux_mcp/tools/batch_tools.py
  • src/libtmux_mcp/tools/buffer_tools.py
  • src/libtmux_mcp/tools/env_tools.py
  • src/libtmux_mcp/tools/hook_tools.py
  • src/libtmux_mcp/tools/option_tools.py
  • src/libtmux_mcp/tools/pane_tools/__init__.py
  • src/libtmux_mcp/tools/pane_tools/capture_since.py
  • src/libtmux_mcp/tools/pane_tools/copy_mode.py
  • src/libtmux_mcp/tools/pane_tools/io.py
  • src/libtmux_mcp/tools/pane_tools/layout.py
  • src/libtmux_mcp/tools/pane_tools/lifecycle.py
  • src/libtmux_mcp/tools/pane_tools/meta.py
  • src/libtmux_mcp/tools/pane_tools/pipe.py
  • src/libtmux_mcp/tools/pane_tools/search.py
  • src/libtmux_mcp/tools/pane_tools/state.py
  • src/libtmux_mcp/tools/pane_tools/wait.py
  • src/libtmux_mcp/tools/server_tools.py
  • src/libtmux_mcp/tools/session_tools.py
  • src/libtmux_mcp/tools/wait_for_tools.py
  • src/libtmux_mcp/tools/window_tools.py
  • tests/__init__.py
  • tests/conftest.py
  • tests/docs/__init__.py
  • tests/docs/_snapshots.py
  • tests/docs/conftest.py
  • tests/docs/test_compatibility.py
  • tests/docs/test_topic_contracts.py
  • tests/docs/test_widgets.py
  • tests/test_batch_tools.py
  • tests/test_buffer_tools.py
  • tests/test_cli.py
  • tests/test_env_tools.py
  • tests/test_history.py
  • tests/test_hook_tools.py
  • tests/test_mcp_swap.py
  • tests/test_middleware.py
  • tests/test_option_tools.py
  • tests/test_package_metadata.py
  • tests/test_pane_tools.py
  • tests/test_prompts.py
  • tests/test_resources.py
  • tests/test_resources_integration.py
  • tests/test_retired_vocabulary.py
  • tests/test_server.py
  • tests/test_server_tools.py
  • tests/test_session_tools.py
  • tests/test_spawn_shell_history.py
  • tests/test_spawn_tools_history.py
  • tests/test_tmux_format_arguments.py
  • tests/test_tool_annotations.py
  • tests/test_utils.py
  • tests/test_wait_for_tools.py
  • tests/test_wait_policy.py
  • tests/test_window_tools.py

Reproduce

Run from a clone containing both revisions with bash, uv 0.12.0, hyperfine 1.20.0 and the utilities used below.

$ bash <<'SH'
set -euo pipefail
base=8014a533da7b9883f88943caaf936b7de8e5fa89
candidate=180e8c4f527c89fc4a7d4f07d3642b5e2beb81c1
work=$(mktemp -d)
results=$(mktemp -d)
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
files=(.github/scripts/test_tmux_build.py .github/scripts/tmux_build.py conftest.py docs/__init__.py docs/_ext/__init__.py docs/_ext/widgets/__init__.py docs/_ext/widgets/_assets.py docs/_ext/widgets/_base.py docs/_ext/widgets/_directive.py docs/_ext/widgets/_discovery.py docs/_ext/widgets/_prehydrate.py docs/_ext/widgets/mcp_install.py docs/conf.py scripts/mcp_swap.py src/libtmux_mcp/__about__.py src/libtmux_mcp/__init__.py src/libtmux_mcp/__main__.py src/libtmux_mcp/_history.py src/libtmux_mcp/_tmux_proc.py src/libtmux_mcp/_utils.py src/libtmux_mcp/_wait_policy.py src/libtmux_mcp/middleware.py src/libtmux_mcp/models.py src/libtmux_mcp/prompts/__init__.py src/libtmux_mcp/prompts/recipes.py src/libtmux_mcp/resources/__init__.py src/libtmux_mcp/resources/hierarchy.py src/libtmux_mcp/resources/viewer.py src/libtmux_mcp/server.py src/libtmux_mcp/tools/__init__.py src/libtmux_mcp/tools/batch_tools.py src/libtmux_mcp/tools/buffer_tools.py src/libtmux_mcp/tools/env_tools.py src/libtmux_mcp/tools/hook_tools.py src/libtmux_mcp/tools/option_tools.py src/libtmux_mcp/tools/pane_tools/__init__.py src/libtmux_mcp/tools/pane_tools/capture_since.py src/libtmux_mcp/tools/pane_tools/copy_mode.py src/libtmux_mcp/tools/pane_tools/io.py src/libtmux_mcp/tools/pane_tools/layout.py src/libtmux_mcp/tools/pane_tools/lifecycle.py src/libtmux_mcp/tools/pane_tools/meta.py src/libtmux_mcp/tools/pane_tools/pipe.py src/libtmux_mcp/tools/pane_tools/search.py src/libtmux_mcp/tools/pane_tools/state.py src/libtmux_mcp/tools/pane_tools/wait.py src/libtmux_mcp/tools/server_tools.py src/libtmux_mcp/tools/session_tools.py src/libtmux_mcp/tools/wait_for_tools.py src/libtmux_mcp/tools/window_tools.py tests/__init__.py tests/conftest.py tests/docs/__init__.py tests/docs/_snapshots.py tests/docs/conftest.py tests/docs/test_compatibility.py tests/docs/test_topic_contracts.py tests/docs/test_widgets.py tests/test_batch_tools.py tests/test_buffer_tools.py tests/test_cli.py tests/test_env_tools.py tests/test_history.py tests/test_hook_tools.py tests/test_mcp_swap.py tests/test_middleware.py tests/test_option_tools.py tests/test_package_metadata.py tests/test_pane_tools.py tests/test_prompts.py tests/test_resources.py tests/test_resources_integration.py tests/test_retired_vocabulary.py tests/test_server.py tests/test_server_tools.py tests/test_session_tools.py tests/test_spawn_shell_history.py tests/test_spawn_tools_history.py tests/test_tmux_format_arguments.py tests/test_tool_annotations.py tests/test_utils.py tests/test_wait_for_tools.py tests/test_wait_policy.py tests/test_window_tools.py)
old_files=("${files[@]}")
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.11.15)
uv sync "${opts[@]}" --project "$work/base"
export VIRTUAL_ENV="$work/venv" PATH="$work/venv/bin:$PATH" NO_COLOR=1
export XDG_CACHE_HOME="$work/xdg-cache" XDG_CONFIG_HOME="$work/xdg-config"
status=0
(cd "$work/base" && mypy --python-executable "$work/venv/bin/python" --config-file pyproject.toml --cache-dir "$work/trunk-cache" -- "${old_files[@]}") > "$results/mypy-trunk.txt" 2>&1 || status=1
(cd "$work/base" && mypy --python-executable "$work/venv/bin/python" --config-file pyproject.toml --cache-dir "$work/native-cache" .) > "$results/mypy-trunk-native-1.txt" 2>&1 || status=1
(cd "$work/base" && mypy --python-executable "$work/venv/bin/python" --config-file pyproject.toml --cache-dir "$work/native-cache" .github/scripts) > "$results/mypy-trunk-native-2.txt" 2>&1 || status=1
project=$("$work/venv/bin/python" -c 'import sys,tomllib; print(tomllib.load(open(sys.argv[1], "rb"))["project"]["name"])' "$work/base/pyproject.toml")
uv sync "${opts[@]}" --project "$work/candidate" --reinstall-package "$project"
uv pip list --python "$work/venv/bin/python" --format json | jq -r '.[] | "\(.name)==\(.version)"' > "$results/candidate-constraints.txt"
uv pip install --python "$work/venv/bin/python" --constraints "$results/candidate-constraints.txt" ast-serialize==0.13.1 librt==0.17.0 mypy==2.4.1 mypy-extensions==1.2.0 pathspec==1.1.1 types-regex==2026.11.19.20261122
uv pip check --python "$work/venv/bin/python"
cd "$work/candidate"
cp "$work/base/pyproject.toml" .bench-trunk-mypy.toml
mypy=("$work"/venv/bin/mypy --python-executable "$work"/venv/bin/python --config-file "$work"/candidate/.bench-trunk-mypy.toml --cache-dir "$work"/mypy-cache --)
ty=("$work"/venv/bin/ty check --python "$work"/venv/bin/python --python-version 3.11 --)
for mode in diagnostics cold warm; do
  for tool in mypy ty; do
    declare -n cmd=$tool
    cache="$work/mypy-cache"
    [[ $tool == mypy ]] || cache="$XDG_CACHE_HOME"
    if [[ $mode == diagnostics ]]; then
      rm -rf "$cache"
      for state in empty repeat; do
        diag=("${cmd[@]}")
        if [[ $tool == ty ]]; then
          diag=("${cmd[@]:0:${#cmd[@]}-1}" --output-format concise --)
        fi
        "${diag[@]}" "${files[@]}" > "$results/$tool-$state.txt" 2>&1 || status=1
      done
      continue
    fi
    controls=()
    if [[ $mode == cold ]]; then
      printf -v clear '%q ' rm -rf "$cache"
      controls=(--prepare "$clear")
    else
      for pass in 1 2; do "${cmd[@]}" "${files[@]}" >/dev/null 2>&1 || status=1; done
    fi
    printf -v command '%q ' "${cmd[@]}" "${files[@]}"
    json="$results/$tool-$mode.json"
    hyperfine --shell=none \
      --runs 8 \
      --ignore-failure \
      --command-name "$tool-$mode" \
      --export-json "$json" \
      "${controls[@]}" "$command"
    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

Checks on 55cbf6ea9b8d

Skipped — release · types · release · build.

Passed — build (3.15, 3.2a) · build (3.15, 3.3a) · build (3.15, 3.8) · build (3.15, 3.4) · build (3.15, 3.5) · types (3.15) · build (3.15, 3.6) · build (3.15, master) · types (3.11).

tony added 4 commits November 29, 2026 12:15
…n endpoints

why: The installed MCP dependencies, documentation and hidden build helpers must resolve in a single project check.

what:
- Pin ty and preserve the published libtmux dependency version.
- Include the documentation and build helpers and enforce authored function annotations.
- Update development commands and run the type matrix alongside the runtime suite.
why: Tool registration, wire validation and tmux dispatch use different contracts that should remain visible to callers and tests.

what:
- Narrow parsed environment fields and retain command dispatch on the live tmux instance.
- Exercise invalid tool requests through a local FastMCP client and resolve the owned fixture socket.
- Use the installed documentation extension metadata support and current context-manager annotations.
why: The corner fixture exercises valid input, and the development environment now provides typed Docutils nodes.

what:
- Annotate the fixture with the tool's PaneCorner type.
- Remove the redundant suppressions from the fixture and docs widget.
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.
@codecov-commenter

codecov-commenter commented Nov 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.67%. Comparing base (8014a53) to head (55cbf6e).

Files with missing lines Patch % Lines
scripts/mcp_swap.py 0.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #164      +/-   ##
==========================================
- Coverage   87.03%   86.67%   -0.36%     
==========================================
  Files          47       47              
  Lines        3964     3970       +6     
  Branches      601      603       +2     
==========================================
- Hits         3450     3441       -9     
- Misses        354      367      +13     
- Partials      160      162       +2     

☔ 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.

why: The supported libtmux release defines variadic commands on its shared command mixin. Referring to that interface preserves each object’s socket, target, return value, and method overrides.

what:
- Use the shared receiver directly where only cmd is needed.
- Forward string command arguments on the original object in mixed-use calls.
@tony
tony marked this pull request as ready for review November 29, 2026 21:29
why: The unreleased changelog links contributors to the reviewed tooling and behavior changes.

what:
- Record the migration in the existing unreleased section and link its pull request.
@tony
tony merged commit 4588031 into main Nov 29, 2026
13 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.

Move Python type checking from mypy to ty

2 participants