Programming

ty Python Type Checker: Install and Benchmark vs mypy, Pyright

The ty Python type checker finished a cold run over the 54-file FastAPI package in 2.1 seconds. On the same files, mypy needed 11.4 seconds and Pyright 10.1 seconds. These are our own hyperfine numbers for ty 1.0.0 (benchmarked December 2026 on Ubuntu 26.04), the first stable release of the Rust type checker from Astral. We ran them on a 4 vCPU cloud VM against a FastAPI checkout pinned to a tagged commit.

Original content from computingforgeeks.com - post 201662

Warm runs change the picture for mypy. With its incremental cache in place, mypy came down to 358 ms against 269 ms for ty. Pyright keeps no cache between command line runs, so it still took 7.5 seconds. Below are the full tables and how each number was taken, then where the three checkers disagree on the same code. After that come the steps to install ty, configure it in pyproject.toml, migrate mypy to ty with --add-ignore and a baseline, and connect the language server to VS Code and Neovim.

ty vs mypy vs Pyright: measured results

ty was the fastest of the three in all four configurations we measured. Its lead is large on a cold cache and small on a warm one against mypy. Target A is the fastapi/ package alone (54 files, 23,803 lines). Target B adds the test suite, fastapi tests, for 712 files and about 123,000 lines. Each cell is the hyperfine mean ± standard deviation.

Target and cachetymypyPyrightty speedup vs mypyty speedup vs Pyright
A, cold (5 runs)2.125 s ± 0.51011.425 s ± 0.39710.090 s ± 0.5385.38x4.75x
A, warm (10 runs)268.8 ms ± 3.8357.8 ms ± 6.97.513 s ± 0.0741.33x27.95x
B, cold (5 runs)3.269 s ± 0.06645.093 s ± 1.31327.389 s ± 0.65613.79x8.38x
B, warm (10 runs)908.3 ms ± 23.8957.5 ms ± 15.019.319 s ± 0.2321.05x21.27x

Memory follows the same order. We took peak resident set size from one /usr/bin/time -v run per checker after the hyperfine runs, so treat these as single samples rather than means. Those runs did not clear caches first, so .mypy_cache was present. ty peaked at about a third of the mypy figure on target A and 28 percent on target B, and under a quarter of the Pyright figure on both. Figures are MiB, converted from the KB that GNU time reports.

Targetty peak RSSmypy peak RSSPyright peak RSS
A, fastapi/119 MiB (121,632 KB)365 MiB (374,084 KB)508 MiB (520,400 KB)
B, fastapi + tests241 MiB (246,316 KB)856 MiB (876,692 KB)1,083 MiB (1,109,408 KB)

Below is the raw hyperfine output behind the first row. The 0.510 s deviation on ty comes from a wide range: the fastest run took 1.772 s and the slowest 3.003 s, well above the 2.125 s mean. mypy and Pyright varied by under 6 percent of their means, so the ty cold figure is the least stable number in the table.

hyperfine cold cache benchmark of ty check, mypy and pyright on FastAPI

Quote the summary line, where ty ran 5.38 ± 1.30 times faster than mypy and 4.75 ± 1.17 times faster than Pyright on a cold cache. The wide error bars come from the ty outlier, not from the slower tools.

How each number was taken

Every run used the same VM, the same checkout and the same interpreter, so the differences come from the checkers and not from the environment. The method, metric by metric:

  • Host: GCP e2-standard-4, 4 vCPU AMD EPYC 7B12, 15 GiB RAM, no swap, Ubuntu 26.04.1 LTS. Nothing else ran on the VM during the benchmark.
  • Project: FastAPI at tag 0.165.0 (commit 05e6df7e), dependencies installed with uv sync --group tests --all-extras into a Python 3.11 venv. mypy read the strict config that ships with FastAPI with the Pydantic plugin.
  • Cold: hyperfine --prepare ran sync, dropped the page cache and deleted .mypy_cache before each of 5 runs.
  • Warm: 2 warmup runs, then 10 timed runs with the page cache and .mypy_cache left in place.
  • Exit codes: hyperfine ran with -i because ty and Pyright exit 1 when they report diagnostics. Timing is unaffected.

Step 7 below has the exact commands, so you can rerun the matrix on your own hardware and your own repository. Expect different absolute numbers on other CPUs and disks; we only measured this one VM.

What the numbers mean for CI and editors

A fresh CI runner sees the cold rows. A runner that starts from a clean checkout has no .mypy_cache, so mypy pays its full 11.4 s on target A and 45.1 s on target B on every push. ty paid 2.1 s and 3.3 s for the same work. On target B that is 41.8 s saved per job before any cache restore step, which is the case where switching pays off the fastest.

Warm rows explain why some teams see little difference locally. The incremental mypy cache for target A was 20 MB on disk, and with it in place mypy finished within 89 ms of ty. On target B the gap shrank to 49 ms, which is 5 percent. If your mypy cache survives between runs and the diff is small, the speed argument for switching is weak and the case rests on diagnostics and the editor. We checked the cache directories after the runs: ty and Pyright left nothing behind, so the ty warm number is its plain run time with the files already in the page cache.

Pyright is the slow one on repeat runs. Its CLI does no incremental work between invocations, so 7.5 s and 19.3 s are the floor for a command line run. The Pyright language server keeps state in memory, which is why it feels fast in an editor despite these numbers. None of this tells you how ty compares with Pyrefly or Zuban, which we did not test. The published Astral speed multipliers compare ty only with those two Rust checkers, and we did not try to reproduce them.

What the ty Python type checker is and what the stable release changed

ty is a static type checker and language server for Python, written in Rust by Astral, the company behind uv and the Ruff linter and formatter. It reads the same annotations mypy and Pyright read, but it has its own rule names, its own suppression comment (# ty: ignore[rule]) and its own configuration under [tool.ty]. The 1 December release ended the beta, and Astral now recommends it for production use.

The headline figures in the ty release notes and the announcement are Astral-reported, and we did not measure them. Astral reports the following:

  • Speed: fastest type checker on 16 of 18 benchmark projects, 1.46x faster than Pyrefly and 3.56x faster than Zuban by geometric mean.
  • Conformance: passes 95% of test files in Python’s typing conformance suite, up from 29% at beta, compared with 57% for mypy.
  • OpenAI: ty is the default type checker there, and migrating gave a median 24x speedup and a 73% cut in peak memory.
  • Downloads: monthly PyPI downloads went from 1.7M in October 2025 to 49.6M in October 2026, against 198.7M for mypy.

The features that matter for a migration are the new ones: --fix, --add-ignore, diagnostic baselines (marked preview), built-in Pydantic, Django, attrs and pytest support, and stricter rules such as the opt-in unsound-return, plus redundant-condition, which warns by default. The versioning policy also changes here: patch releases are bug fixes only, and minor releases may add new type errors. That is a reason to pin the version in CI, which Step 1 does.

Step 1: Install ty with uv, uvx or pip

ty ships as a single binary inside a platform wheel, so any Python installer works. We used uv tool install, which puts ty on your PATH in its own isolated environment. If uv is not on the machine yet, start with the uv command cheat sheet. Pin the version so a minor release does not change your CI results overnight:

uv tool install [email protected] #https://github.com/astral-sh/ty/releases
ty --version

The download is 17.2 MiB and installs one executable:

uv tool install ty@1.0.0 output and ty --version printing ty 1.0.0 on Ubuntu 26.04

For a one-off check or a CI step, uvx runs ty from the uv cache without installing it. This is the form to use in a pipeline, because the pin lives in the command:

uvx [email protected] --version #https://github.com/astral-sh/ty/releases

It prints the same version string as the installed copy:

ty 1.0.0

Plain pip works too, inside a virtual environment. Ubuntu marks its system Python as externally managed, so create a venv first. Our Python on Ubuntu 26.04 guide explains why pip refuses the system interpreter:

python3 -m venv ~/pipty
~/pipty/bin/pip install ty==1.0.0 #https://github.com/astral-sh/ty/releases
~/pipty/bin/ty --version

pip reports the install and the binary answers with the same version:

Installing collected packages: ty
Successfully installed ty-1.0.0
ty 1.0.0

For the comparison we installed mypy and Pyright the same way, with uv tool install. The Pyright PyPI wrapper downloads its own Node.js on the first run, which added a one-time delay that is not in any timing above. These are the versions behind every number in this article:

mypy --version
pyright --version

The first Pyright call shows the Node.js download line:

mypy 2.4.1 (compiled: yes)
 * Install prebuilt node (26.14.0) ..... done.
pyright 1.1.414

On Fedora, our Python and uv on Fedora guide gets the toolchain in place first, and every ty command after that works the same. On a Mac, start from our Mac developer setup and then install ty the same way.

Step 2: Run ty check on a real project

ty check with no arguments checks the project that contains the current directory and finds the virtual environment on its own. It looks for .venv in the project root or an active VIRTUAL_ENV. We cloned FastAPI, pinned the tag and installed its dependencies so that ty, mypy and Pyright all resolved the same third-party packages:

git clone https://github.com/fastapi/fastapi.git ~/fastapi
cd ~/fastapi
git checkout 0.165.0
uv sync --group tests --all-extras

With the venv in place, check the package. The concise format prints one line per diagnostic, which is easier to count and to diff between runs:

ty check fastapi --output-format concise

ty reported 16 diagnostics on the package: 3 errors and 13 warnings. These are four of them, one per rule:

fastapi/openapi/models.py:351:5: error[incompatible-mutable-override] Invalid override of attribute `scheme`: Override does not accept writes of type `str`
fastapi/dependencies/utils.py:132:20: warning[redundant-condition] Nonempty string `__version__` is always truthy (has type `Literal["0.0.32"]`)
fastapi/_compat/shared.py:26:71: warning[renamed-rule-in-ignore-comment] Rule `unresolved-attribute` has been renamed to `missing-attribute`
fastapi/telemetry/_api.py:201:2: warning[deprecated] The overload of `contextmanager` is deprecated: Annotating the return type as `-> Iterator[Foo]` with `@contextmanager` is deprecated. Use `-> Generator[Foo]` instead.

The renamed-rule-in-ignore-comment warnings are a migration artifact. FastAPI already carries # ty: ignore[...] comments written against the rule names of the beta it pins, and some of those rules were renamed before the stable release. The old names still suppress, so nothing breaks, but ty prints the new name for each one. --fix rewrites them to the new name, while --add-ignore only silences the warning. The rule breakdown across the three checkers looks like this:

Diagnostic counts by rule for ty, pyright and mypy on the FastAPI package

mypy reported nothing, which is expected, because the FastAPI CI runs mypy in strict mode and keeps it clean. Pyright found 54 errors, half of them reportTypedDictNotRequiredAccess in the telemetry module. ty and mypy reported none of those on this code.

Step 3: Compare the diagnostics with mypy and Pyright

The three checkers agree on obvious type errors and disagree on everything at the edges. On the same pinned FastAPI checkout, the totals were far apart:

Targettymypy (FastAPI strict config)Pyright (defaults)
fastapi/ (54 files)16 (3 errors, 13 warnings)054 errors, 1 warning
fastapi + tests (712 files)385,103 errors in 546 files171 errors, 1 warning

The 5,103 mypy errors on target B do not mean the tests are badly typed. The strict FastAPI mypy config was written for the package, and the tests are mostly unannotated functions that strict mode rejects wholesale. ty and Pyright check unannotated code without demanding annotations, so their counts stay small. Compare checkers on a config each one was set up for, or the counts will mislead you.

To see the rule differences in isolation, we wrote a small library with uv init --lib tydemo and planted known bugs in src/tydemo/core.py. The last five lines test how each checker treats suppression comments:

import json


def parse(raw):
    data = json.loads(raw)
    return data["count"] + "items"


def total(xs: list[int]) -> int:
    return sum(xs) + "1"


class Config:
    def __init__(self) -> None:
        self.port = 8080


def port_of(c: Config) -> str:
    return c.port


def untyped_body():
    x: int = "hello"
    return x


def risky(flag: bool) -> int:
    if flag:
        return 1


n: int = "3"  # type: ignore
m: int = "4"  # type: ignore[assignment]
k: int = "5"  # ty: ignore[invalid-assignment]
j: int = "6"  # type: ignore[arg-type]
ok: int = 7  # type: ignore

ty reported 7 diagnostics, mypy 5 errors and Pyright 5 errors. The table lines them up by source line, which is where a migration actually breaks:

Line and codetymypy (default)Pyright
6, data["count"] + "items" on untyped JSONsilentsilentsilent
10, sum(xs) + "1"unsupported-operator[operator]reportOperatorIssue
19, returns int from -> strinvalid-explicit-return[return-value]reportReturnType
23, bad assignment in an untyped functioninvalid-assignmentnote only, body not checkedreportAssignmentType
27, missing return pathinvalid-implicit-return[return]reportReturnType
33, # type: ignore[assignment]error, not suppressedsuppressedsuppressed
34, # ty: ignore[invalid-assignment]suppressederrorerror
35, # type: ignore[arg-type] (wrong code)errorerror, code not coveredsuppressed
36, # type: ignore on valid codeunused-type-ignore-comment warningsilentsilent

Two results matter most. mypy skips the body of an unannotated function by default and only prints a note for line 23. With --check-untyped-defs it reported 6 errors and now also flagged line 23. ty checks every function body, so a codebase that relied on that mypy default will see new errors on day one. None of the three flagged parse(), because json.loads returns Any and all three treat Any as compatible with everything.

How type: ignore comments carry over

A blanket # type: ignore works in ty, and a coded # type: ignore[assignment] does not. ty respects the blanket form, but mypy error codes mean nothing to it, so it ignores any code that is not a ty rule. A separate test file confirmed the rule:

a: int = "1"  # type: ignore[arg-type, ty:invalid-assignment]
b: int = "2"  # ty: ignore[invalid-assignment]
c: int = 3  # ty: ignore[invalid-assignment]
d: int = "4"  # type: ignore
e: int = "5"  # type: ignore[assignment]

ty suppressed lines 1, 2 and 4. It flagged line 3 as an unused suppression and line 5 as an error. The results across all three checkers:

  • ty: a ty: prefixed code inside type: ignore[...] suppresses (line 1). Setting respect-type-ignore-comments = false turned lines 1 and 4 into errors as well.
  • mypy: errors on lines 1 and 2. The mixed comment on line 1 does not name assignment, so mypy reports it, and with --warn-unused-ignores it also calls the comment unused.
  • Pyright: an error on line 2 only. It treats any type: ignore as blanket and ignores the codes inside it.

In practice, when one line must satisfy both mypy and ty during a migration, write two comments, # type: ignore[assignment] # ty: ignore[invalid-assignment]. That is exactly the form --add-ignore generates in Step 5, and it keeps both checkers quiet without one breaking the other.

Step 4: Configure [tool.ty] in pyproject.toml

ty reads [tool.ty] from pyproject.toml, or a standalone ty.toml with the same keys. Open the project file:

vim pyproject.toml

Append the ty sections. This is the exact block we tested: it pins the target Python version, adds the tests directory, changes the severity of three rules and pins error-on-warning to its default of true, so a future default change cannot quietly let warnings pass:

[tool.ty.environment]
python-version = "3.12"

[tool.ty.src]
include = ["src", "tests"]

[tool.ty.rules]
possibly-unresolved-reference = "warn"
unused-ignore-comment = "error"
unsound-return = "warn"

[tool.ty.terminal]
error-on-warning = true

Each rule takes "error", "warn" or "ignore". The same severities work on the command line with --error, --warn and --ignore, which is handy for trying a rule before committing it. By this point our demo had grown a test file under tests/ and a few more modules, and with this config it reported 13 diagnostics and exited 1, one of them in the test file. Your count will differ with your own files. To relax a rule for part of the tree, add an override at the end of the file:

[[tool.ty.overrides]]
include = ["tests/**"]

[tool.ty.overrides.rules]
invalid-assignment = "ignore"

The tests diagnostic disappeared and the count fell to 12, with every src/ diagnostic unchanged. Overrides are the clean way to hold tests to a looser standard than library code, instead of sprinkling suppression comments through fixtures.

Exit codes and error-on-warning

Warnings fail the run by default. We tested every combination on a file with two warnings and no errors, and the exit code is what a CI job sees:

FlagsExit code with 2 warnings
none (default)1
--error-on-warning1
--exit-zero-on-warning0
--exit-zero0, even with errors
--error-on-warning --exit-zero2, flags rejected as conflicting

Use --exit-zero-on-warning during a migration when you want warnings visible in the log but not blocking merges. Exit code 2 means ty itself failed, such as a bad flag or an invalid config file, and not that it found type errors.

Step 5: Migrate from mypy with –add-ignore and a baseline

ty offers two ways to adopt it on a codebase that already has errors. You can write a suppression comment on every current diagnostic, or record the diagnostics in a baseline file and fail only on new ones. We ran both on the demo and on FastAPI. The demo counts below come from copies of the Step 3 project taken before the Step 4 config was added. Comments are visible in the code and survive refactors, while a baseline keeps the source untouched.

Suppress current errors with –add-ignore

Commit or stash your work first, because --add-ignore edits files in place:

ty check --add-ignore

On the demo it printed Added 7 ignore comments. Where a line already had a mypy comment, ty appended its own instead of replacing it, which produces the two-comment form from Step 3:

git diff after ty check --add-ignore showing ty: ignore comments appended to each line

It did not touch the two unused comments it had warned about, which is the job of --fix. On a copy of FastAPI, ty check fastapi --python ~/fastapi/.venv --add-ignore printed All checks passed! and Added 16 ignore comments, changing 9 files with 16 insertions and 16 deletions. Lines that already had a # ty: ignore[...] got the new rule added inside the same brackets, for example ty: ignore[unresolved-attribute, renamed-rule-in-ignore-comment]. The second run exited 0.

Fail only on new errors with a baseline (preview)

Astral marks baselines as a preview feature in this release, so the file format may change. On our run the flags worked without any preview opt-in. Record the current diagnostics:

ty check --update-baseline --baseline ty-baseline.json

Then point the config at the file so a plain ty check uses it:

[tool.ty]
baseline = "ty-baseline.json"

The screenshot shows the full cycle. The baseline swallowed all 9 existing diagnostics, then a new function with a wrong return type was the only thing reported:

ty check --update-baseline writing ty-baseline.json, then a new error reported on top of the baseline

The baseline stores each diagnostic as a rule name, start and end column and line count per file, and records no line numbers at all. The 9 entries became a 63-line JSON file, and rerunning ty check --update-baseline after the new bug raised it to 10 entries and an exit code of 0. Review that update in code review like any other change, because it is how errors get accepted.

Clean up suppressions with –fix

In our tests --fix removed unused suppression comments and did not change any code to fix a type error. The rules reference adds that it also rewrites renamed rule names inside ty: ignore comments. Our test file held a clean Optional[int] function plus two needless suppressions, a: int = 1 # ty: ignore[invalid-assignment] and b: int = 2 # type: ignore, and it fixed both:

ty check src/tydemo/fixme.py --fix

ty prints how many it fixed and how many remain:

Found 2 diagnostics (2 fixed, 0 remaining).

Run it after the migration settles. Once mypy is gone from CI, the leftover mypy-only comments become dead weight, and --fix removes any that suppress nothing for ty.

Turn on unsound-return when the code is clean

unsound-return is one of the stricter rules and is off by default. It catches a function annotated -> int that returns a value inferred as Any, which ty accepts by default. We tested it on a file where count() returns the result of a json.loads wrapper:

ty check --warn unsound-return flagging a return of Any from a function annotated int

The default run passed. With --warn unsound-return, ty pointed at the Any return and suggested an assert to narrow it. Combined with --exit-zero-on-warning, the same run exited 0, which is a safe way to see how often the rule fires. Enable it after the baseline is empty, since it flags every annotated function that returns an Any value.

Run ty in CI

For GitHub Actions, the github output format turns each diagnostic into an annotation on the pull request diff. Put this in a workflow run step, after the step that creates the venv:

uvx [email protected] check --output-format github #https://github.com/astral-sh/ty/releases

Each diagnostic becomes one workflow command line. The first line from our demo run:

::error title=ty (unsupported-operator),file=/home/lab/tydemo/src/tydemo/core.py,line=10,col=12,endLine=10,endColumn=25::src/tydemo/core.py:10:12: unsupported-operator: Operator `+` is not supported between objects of type `int` and `Literal["1"]`%0A  src/tydemo/core.py:10:12: Has type `int`%0A  src/tydemo/core.py:10:22: Has type `Literal["1"]`

ty also emits gitlab, junit and sarif, so the same pattern works on GitLab or with a code scanning upload. Keep mypy running next to ty until the baseline or the ignore comments are stable, then drop it. Pinning tools this way is the same discipline our PyPI package malware check applies to dependencies.

Step 6: Set up the ty language server in VS Code and Neovim

The language server is the same binary, since ty server speaks LSP over stdio and takes no options. Any editor with an LSP client can start it. The CLI and the editor read the same [tool.ty] config, so the diagnostics match.

VS Code extension

Install the official extension from the marketplace, or from a terminal. On our Ubuntu VM the code CLI came from sudo snap install code --classic, which gave VS Code 1.148.0:

code --install-extension astral-sh.ty

On our VM it installed cleanly:

Installing extension 'astral-sh.ty'...
Extension 'astral-sh.ty' v2026.126.0 was successfully installed.

According to Astral’s editor documentation, the extension sets python.languageServer to "None" as a default, which turns off Pylance so you do not run two Python language servers. To keep Pylance for hover and completion and use ty only for diagnostics, override both settings in settings.json:

{
  "python.languageServer": "Pylance",
  "ty.disableLanguageServices": true
}

Leave the default if you want ty for everything. Running two full Python language servers side by side gives you two sets of diagnostics with different rule names for the same line, which makes the editor harder to read than either one alone.

Neovim with nvim-lspconfig

Neovim 0.11 and later has vim.lsp.enable() built in, and nvim-lspconfig ships the ty definition. Ubuntu 26.04 packages Neovim 0.11.6, so sudo apt install -y neovim is enough. We installed nvim-lspconfig as a plain package, without a plugin manager:

git clone --depth 1 https://github.com/neovim/nvim-lspconfig ~/.local/share/nvim/site/pack/plugins/start/nvim-lspconfig

Then open the init file in your editor.

vim ~/.config/nvim/init.lua

One line enables the server:

vim.lsp.enable("ty")

The bundled lsp/ty.lua runs ty server for Python buffers and finds the project root from ty.toml, pyproject.toml, setup.py, setup.cfg, requirements.txt or .git. With core.py from the demo open, :checkhealth vim.lsp showed the client attached:

vim.lsp: Active Clients ~
- ty (id: 1)
  - Version: 1.0.0
  - Root directory: ~/tydemo
  - Command: { "ty", "server" }
  - Settings: {}
  - Attached buffers: 1

The buffer held the same 7 diagnostics as ty check, from unsupported-operator on line 10 to the unused blanket type: ignore on line 36. If the client does not attach, run which ty from the shell that starts Neovim: the server must be on that PATH, and uv tool install puts it in ~/.local/bin.

Step 7: Reproduce the benchmark with hyperfine

hyperfine is in the Ubuntu archive (we used 1.19.0), and GNU time already lived at /usr/bin/time on our image:

sudo apt update && sudo apt install -y hyperfine git build-essential

Do not activate FastAPI’s .venv for these runs. uv sync installs FastAPI’s own pinned dev tools into it, and on our checkout that meant ty 0.0.78 and mypy 2.3.1. With the venv active, ty resolves to the old beta and you benchmark the wrong binary. Check that ty --version prints 1.0.0 in the shell you run hyperfine from.

The cold run clears the page cache and the mypy cache before every timed run, so it needs sudo for the cache drop. Run it from the FastAPI checkout after Step 2:

hyperfine -i --prepare 'sync; echo 3 | sudo tee /proc/sys/vm/drop_caches >/dev/null; rm -rf .mypy_cache' --runs 5 'ty check fastapi' 'mypy --python-executable .venv/bin/python fastapi' 'pyright --pythonpath .venv/bin/python fastapi'

The warm run keeps both caches and adds two warmup runs:

hyperfine -i --warmup 2 --runs 10 'ty check fastapi' 'mypy --python-executable .venv/bin/python fastapi' 'pyright --pythonpath .venv/bin/python fastapi'

For target B, replace fastapi with fastapi tests in all three commands. Peak memory came from GNU time, one run per checker:

/usr/bin/time -v ty check fastapi 2>&1 | grep -E "Maximum resident|Elapsed"

Look for the maximum resident set size line in the output. On our VM ty peaked at 121,632 KB on target A:

	Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.26
	Maximum resident set size (kbytes): 121632

One trap to avoid on mypy: if it is installed with uv tool install mypy and the project’s config loads the Pydantic plugin, mypy stops with Error importing plugin "pydantic.mypy": No module named 'pydantic'. Install it with the plugin’s package in the tool environment, uv tool install mypy --with pydantic --force, before timing anything, or the mypy numbers measure a crash.

Common ty errors and their fixes

These four messages came up in our lab runs, and each heading below is the text ty prints. Two of them stop the check entirely, while the other two only change what it reports.

error[import-not-found]: Cannot resolve imported module

ty could not find a virtual environment, so it searched only the system site-packages. The diagnostic lists every path it tried, which tells you straight away whether your venv was among them:

error[import-not-found]: Cannot resolve imported module `fastapi`
 --> app.py:1:6
  |
1 | from fastapi import FastAPI
  |      ^^^^^^^
info: Searched in the following paths during module resolution:
info:   1. /home/lab/noenv (first-party code)
info:   2. vendored://stdlib (stdlib typeshed stubs vendored by ty)
info:   3. /usr/local/lib/python3.14/dist-packages (site-packages)
info:   4. /usr/lib/python3.14/dist-packages (site-packages)
info:   5. /usr/lib/python3/dist-packages (site-packages)
info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment

Pass the environment explicitly with --python, or activate it so VIRTUAL_ENV is set. Both forms returned All checks passed! on our run:

ty check app.py --python ~/fastapi/.venv

The same error appears in bulk when you check a project from outside its directory. ty check ~/fastapi/fastapi run from /tmp reported 404 diagnostics, nearly all of them unresolved imports, because ty did not find the project’s .venv. Adding --project ~/fastapi brought it back to the expected 16.

unknown field `pyhton-version`, expected one of `root`, `python-version`

A misspelled key in [tool.ty] stops ty with exit code 2 before it checks anything. A misspelled rule name only produces a warning, so the check runs without the rule you meant to set. The capture shows both cases:

ty failed with unknown field pyhton-version in pyproject.toml and an unknown-rule warning

The unknown-rule warning is easy to miss in a long output, and in our run the misspelled unsound-retrn meant both unsound-return warnings silently vanished. Grep CI logs for unknown-rule after any config change.

error[invalid-syntax]: Cannot use `type` alias statement on Python 3.9

ty parses code against the configured Python version, not the interpreter that runs it. A file using type aliases and match failed when we checked it with --python-version 3.9:

error[invalid-syntax]: Cannot use `type` alias statement on Python 3.9 (syntax was added in Python 3.12)
 --> newsyntax.py:1:1
  |
1 | type Pair = tuple[int, int]
  | ^^^^
info: Python 3.9 was assumed when parsing syntax because it was specified on the command line

Set python-version under [tool.ty.environment] to the oldest version you support. Without it, ty takes the version from requires-python or the detected environment, so a library that claims 3.9 support gets exactly this error on newer syntax.

warning[unused-type-ignore-comment]: Unused blanket `type: ignore` directive

ty warns about a # type: ignore on a line it finds no error on. Because warnings exit 1 by default, a mypy-era codebase can fail CI on this alone. Run ty check --fix to delete the dead comments, or set the rule to "ignore" while mypy still needs them. Dependency upgrades change the types ty sees, so a comment that was needed last month can become unused after one. Security fixes force those upgrades on short notice, as in our Python ssl SNI callback CVE writeup, so expect this warning to come back after each round.

What to watch after switching

Watch CI wall time on a cold runner first. That is where our measurement says the gain is: 9.3 s saved per run on a 54-file package and 41.8 s on a 712-file tree against mypy, with no cache to manage. If your pipeline already restores .mypy_cache and most commits touch few files, expect the warm row instead, with mypy taking 5 to 33 percent longer than ty, and decide on diagnostics rather than speed.

Then watch the diagnostic count after each ty minor release. Under the Astral versioning policy, minor releases may add new type errors, so pin the version in uvx and the tool install and bump it in its own pull request. The renamed-rule-in-ignore-comment warnings we hit on FastAPI show the cost of skipping that: four stale suppressions from beta rule names. Finally, compare the counts in the second table above against your own repository before removing mypy. The checkers disagree enough on unannotated code and ignore comments that a parallel run of a week or two will show which differences your codebase actually depends on.

Keep reading

Install GitHub CLI (gh) on Linux, macOS, and Windows Programming Install GitHub CLI (gh) on Linux, macOS, and Windows Best Linux Laptops for Programming and Developers (2026) Programming Best Linux Laptops for Programming and Developers (2026) How To Install Python 3.13 on Debian 13 (Trixie) Debian How To Install Python 3.13 on Debian 13 (Trixie) Python CVE-2026-19445: Check and Patch the sni_callback Flaw Programming Python CVE-2026-19445: Check and Patch the sni_callback Flaw React2Shell in Next.js: Check, Patch and Rotate After React2Keys Programming React2Shell in Next.js: Check, Patch and Rotate After React2Keys Why Create a Software for the Real Estate Market Programming Why Create a Software for the Real Estate Market

Leave a Comment

Press ESC to close