Meet Modi
Back to Blog
·11 min

ty 1.0 found 37 errors in a codebase mypy --strict calls clean

ty vs mypy on Rich: ty 1.0 checked it in 0.20 s to mypy's 1.85 s, then reported 37 errors. 20 sat on lines with a mypy ignore that ty does not honor.

By Meet Modi
PythonDeveloper ToolsType SystemStatic Analysis

Rich, the terminal formatting library, runs mypy in strict mode in its CI. On a fresh clone, mypy 2.4.1 reports 3 errors across its 100 source files. ty 1.0, released by Astral the day before, reports 37. Twenty of those 37 are on lines that already say # type: ignore[something]. ty read the comment and decided it was not talking to ty.

So, ty vs mypy, in one paragraph: ty is much faster (0.20 s against 1.85 s on Rich here, 0.09 s against 0.87 s on httpx), uses less memory, and disagrees with mypy in ways you will have to sort out by hand before it can gate a merge. The disagreements are partly real bugs, partly ty being stricter, and partly mypy-specific comments that ty skips on purpose. ty ships three tools for a migration: --add-ignore, a baseline file, and --fix. I tried all three on Rich, plus the examples from the release post, on a 2 vCPU GitHub Actions runner.

What ty 1.0 is

ty is a Python type checker and language server written in Rust, from the people who make uv and Ruff. It spent the past months in Beta (the last pre-release on PyPI is 0.0.115, from November 30) and turned 1.0.0 on December 1. The release post pitches it against mypy, Pyright, Pyrefly and Zuban, and the repo is MIT licensed.

The numbers Astral gives: fastest on 16 of 18 open source projects in a cold CLI run on an M3 Max, 1.46x faster than Pyrefly and 3.56x faster than Zuban by geometric mean. As a language server, fastest on 14 of 17 projects. On the Python typing conformance suite, 14 false positives and 13 false negatives, down from 224 and 405 at Beta, against mypy's 190 and 109. OpenAI's migration is quoted at a median 24x speedup and 73% less peak memory. All of those are Astral's measurements, and the post itself calls the conformance suite "an imperfect proxy for real-world correctness".

Adoption is the other half of the pitch. PyPI downloads went from 1.7M to 49.6M between October 2025 and October 2026. mypy went from 55.2M to 198.7M in the same window, so mypy is not shrinking, it is just no longer alone. In Astral's audit of the 25,000 most downloaded PyPI packages, 11.6% of the repos that use a type checker use ty.

ty vs mypy speed on a real codebase

I installed ty 1.0.0, mypy 2.4.1, Pyrefly 1.5.1 and Pyright 1.1.414 into one virtualenv with pip, pointed all four at the same interpreter, and ran each one cold three times on Rich (38,348 lines) and httpx (8,827 lines). mypy got --no-incremental and a throwaway cache directory so it could not cheat with a warm cache.

$ /usr/bin/time -f "ty: %e s, %M KB" ty check rich --python venv/bin/python
ty: 0.20 s, 100732 KB
ty: 0.21 s, 100576 KB
ty: 0.21 s, 104916 KB
pyrefly: 0.29 s, 91480 KB
pyrefly: 0.30 s, 90488 KB
mypy: 1.85 s, 221412 KB
mypy: 1.94 s, 221632 KB
pyright: 7.11 s, 440744 KB
pyright: 7.39 s, 436904 KB

# httpx, best of three
ty: 0.09 s, 69268 KB
pyrefly: 0.15 s, 76276 KB
mypy: 0.87 s, 150316 KB
pyright: 2.90 s, 252864 KB

So about 9x faster than cold mypy on Rich and 10x on httpx, with less than half the memory. Pyrefly is close behind on time and slightly lighter on memory on Rich. Pyright's figure includes starting Node through the pip wrapper, so it is not a fair read of Pyright inside an editor, where it stays running.

Two seconds is not a CI problem. Where the gap matters is pre-commit hooks and the editor, where you feel every pause. A repo the size of Rich was never slow under mypy. The 24x figure comes from OpenAI's monorepo, and if your codebase is a few hundred files, do not expect your day to change.

Why ty reports errors mypy ignores

Here is the first error ty printed that mypy did not:

error[missing-union-attribute]: Attribute `fileno` is not defined on `None` in union `TextIOWrapper[_WrappedBuffer] | None`
  --> rich/console.py:74:21
   |
74 |     _STDIN_FILENO = sys.__stdin__.fileno()  # type: ignore[union-attr]
   |                     ^^^^^^^^^^^^^^^^^^^^

mypy calls this error union-attr. ty calls it missing-union-attribute. The comment names mypy's code, so ty treats it as not meant for it. The suppression docs cover this, a little indirectly: a bare # type: ignore suppresses everything on the line, and inside brackets only codes with a ty: prefix count. A small file shows the three cases:

a = None.fileno()  # type: ignore[union-attr]                 # ty reports it
b = None.fileno()  # type: ignore[ty:unresolved-attribute]     # suppressed, plus a warning
c = None.fileno()  # type: ignore                              # suppressed

Line b got its own warning, renamed-rule-in-ignore-comment, because unresolved-attribute is now called missing-attribute. Rule names have already changed at least once, so ignores you write today can start warning after an upgrade.

This is the right call for ty: mypy's codes and ty's rules do not map one to one, and guessing would hide real errors. But every codebase that has been strict under mypy for years is full of coded ignores, because mypy's own warn_unused_ignores and ignore-without-code settings push you that way. Rich has 22 lines with one in rich/, every one of them coded, and 20 of ty's 37 diagnostics land on lines like that.

The other 17

The rest are a mix. Some are fair: a warning that if wrap_justify: is always true, because ty infers its type as a Literal of five non-empty strings, and a few len() and list.append() calls on values ty infers as plain object, where mypy is more forgiving. Some depend on where you run it. rich/_win32_console.py raises ImportError at import time on anything but Windows, so on Linux ty treats the LegacyWindowsTerm class as unreachable and its type as Never:

error[invalid-type-form]: Variable of type `Never` is not allowed in a parameter annotation
 --> rich/_windows_renderer.py:7:60
help: The variable may have been inferred as `Never` because its definition was inferred as being unreachable

$ ty check rich --python-platform all
Found 36 diagnostics

--python-platform all (or win32) makes that one go away. And some are noise for this project: four get_ipython calls that only exist inside Jupyter, and a from .live import Live inside live.py's own if __name__ == "__main__" block, which ty reports as Module rich.live has no member Live.

How to migrate from mypy to ty

ty gives you three ways to get from 37 to zero without fixing 37 things today. I tried each on a copy of Rich.

--fix

$ ty check rich --fix
Found 37 diagnostics (0 fixed, 37 remaining).

Nothing in Rich had an automatic fix. The fixes ty offers on my small test files were for things like a missing import of reveal_type, and that one is labelled unsafe. Do not plan a migration around --fix.

--add-ignore

$ ty check rich --add-ignore
Added 37 ignore comments
 12 files changed, 37 insertions(+), 37 deletions(-)

-    _STDIN_FILENO = sys.__stdin__.fileno()  # type: ignore[union-attr]
+    _STDIN_FILENO = sys.__stdin__.fileno()  # type: ignore[union-attr]  # ty: ignore[missing-union-attribute]

It works. ty passes, mypy still reports the same 3 errors it did before, so the two can run side by side. The cost is lines like the one above, with two checkers' opinions glued to the end, in 12 files.

A ty baseline file

The release post says to run ty check --update-baseline and commit the file. In 1.0.0 that alone fails:

$ ty check rich --update-baseline
ty failed
  Cause: `--update-baseline` requires a baseline path from `--baseline` or configuration

$ ty check rich --baseline ty-baseline.json --update-baseline
Updated baseline `/tmp/dsp/ty/rich2/ty-baseline.json` with 37 diagnostics.

$ ty check rich --baseline ty-baseline.json
All checks passed!

Set it once in config and the flag goes away: baseline = "ty-baseline.json" under [tool.ty] in pyproject.toml. The configuration reference also says the thing the release post does not: "Diagnostic baselines are in preview", and the file format may change between releases.

The file stores, per file, each diagnostic's rule and its start and end column. No line numbers. I wanted to know whether that holds up, so I tried three edits:

  • A new bad return in rich/abc.py: caught, exit 1, one diagnostic.
  • A comment inserted at the top of console.py, shifting every line: still passes. Good, that is the point of leaving line numbers out.
  • Line 74 of console.py duplicated, so the same error at the same columns appears twice in the file: caught. The baseline counts matches, it does not just check that a matching entry exists.

That last one is the case I expected it to miss. It did not. Of the three routes, this is the one I would pick: no source edits, new errors fail, old ones wait.

What ty catches that mypy --strict does not

The release post's best example is a function that claims to return list[str] and actually returns whatever SQLite gives it:

import sqlite3

def usernames(db: sqlite3.Connection) -> list[str]:
    cursor = db.execute("SELECT username FROM users")
    return cursor.fetchall()
$ mypy --strict users.py
Success: no issues found in 1 source file

$ ty check users.py
All checks passed!

$ ty check --warn unsound-return users.py
warning[unsound-return]: Unsound return statement
 --> users.py:6:12
6 |     return cursor.fetchall()
  |            ^^^^^^^^^^^^^^^^^ Inferred as `list[Any]`
info: `list[Any]` is assignable to `list[str]`, but not a subtype of `list[str]`

$ python3 users.py
[('meet',)]

The run shows the bug: a list of tuples, not a list of strings. mypy in strict mode lets it through, because list[Any] is assignable to list[str]. ty only flags it with --warn unsound-return, which is off by default. Turn it on. It is the same class of bug as the API field that came back in three different shapes: the annotation was a promise, and nothing checked the data against it.

The other opt-in worth knowing is return-type-inference. By default ty treats the return type of an unannotated function as Unknown. A def load(path: str): return {"id": 1} revealed as Unknown with the default and dict[str, int] with return-type-inference = "always" under [tool.ty.analysis]. mypy reveals Any for the same thing.

ty vs mypy vs Pyright vs Pyrefly on attribute types

Astral's post shows ty catching a string assigned to an attribute that __init__ set to 3. The exact example works:

class RetryPolicy:
    def __init__(self) -> None:
        self.attempts = 3

policy = RetryPolicy()
policy.attempts = "three"
# ty: error[invalid-assignment]: Object of type `Literal["three"]` is not
#     assignable to attribute `attempts` of type `int`

Then I added one method to the class, def reset(self) -> None: self.attempts = "three". ty now reports nothing, and reveals policy.attempts as Literal["three"]. Pyright behaves the same way. ty and Pyright both build an attribute's type from every assignment inside the class, so one stray assignment in a method widens it to int | str, and the outside assignment becomes legal. mypy flags both lines. Pyrefly keeps the type as int but reports neither. Four checkers, three answers.

None of this is a bug in ty. It is the Pyright model, and there are good reasons for it. But if your team's mental model of Python types came from mypy, this is the kind of difference that passes code review because everyone assumes the checker would have said something.

The catch: what I'd wait on

  • Coded mypy ignores do nothing. Budget for one pass over them, with --add-ignore or a baseline. There is no setting that maps mypy codes to ty rules.
  • Warnings fail the build. ty check exits 1 on a single warning. In CI, either fix them or pass --exit-zero-on-warning, and decide that on purpose.
  • The baseline is preview. The format may change between releases, and in 1.0.0 the command in the release post needs a path it does not mention.
  • Rule names move. unresolved-attribute is already missing-attribute, and old names in ignore comments now warn. Pin the ty version in CI and upgrade on purpose.
  • Platform matters. Without --python-platform, ty checks for the platform it runs on, so Windows-only modules look unreachable on a Linux runner.
  • The headline numbers are Astral's, on an M3 Max, with OpenAI as the showcase user. Mine are from a 2 vCPU runner and two projects. Run it on your own repo before you believe either.
  • I did not test the editor side at all: no browser, no VS Code here. The language server numbers are Astral's only.

If your project depends on how mypy handles a specific library, check that first. The release post lists built-in support for Pydantic, Django, pytest and attrs. Anything else is worth a test before you delete the mypy job.

Should you switch from mypy to ty?

Add it before you replace anything. Pin ty 1.0.0, run it in CI next to mypy with a baseline, turn on --warn unsound-return, and see what it finds on new code for a few weeks. If what ty flags keeps being real, the speed is a bonus and mypy can go. If it is mostly arguments about Literal types and Jupyter globals, you have lost nothing but a baseline file.

Is ty better than mypy?

ty is faster and catches some bugs mypy misses, but it is not a drop-in replacement. On Rich, ty ran in 0.20 s against mypy's 1.85 s, and it flagged an unsound list[Any] return that mypy --strict passes. It also reported 37 errors on code mypy calls clean, mostly because it ignores mypy's coded type: ignore comments. Try it next to mypy first.

Is Astral ty production ready?

Astral says yes. The 1.0 release on December 1, 2026 says it is ready "for production use, for all users", and it is the default type checker at OpenAI. Some parts are still marked preview, including diagnostic baselines and uv script support, and rule names have changed since Beta. Pin the version in CI so an upgrade does not change your results by surprise.

Does ty respect type: ignore comments?

Partly. A bare # type: ignore suppresses every diagnostic on the line, and # type: ignore[ty:rule] works like # ty: ignore[rule]. A mypy-style code such as # type: ignore[attr-defined] does not suppress ty. On Rich, 20 of ty's 37 diagnostics were on lines with a coded mypy ignore. You can turn type: ignore off entirely with respect-type-ignore-comments = false.

How do I migrate from mypy to ty?

Run ty next to mypy and record what it finds today in a baseline. Set baseline = "ty-baseline.json" under [tool.ty], run ty check --update-baseline, commit the file, and new errors will fail while old ones wait. The alternative is ty check --add-ignore, which writes a ty: ignore comment on every current error. The baseline keeps your source clean but is still a preview feature.

ty vs Pyright: which is faster?

ty was faster in my run, by a lot. On Rich, ty took 0.20 s and about 100 MB, Pyright 7.1 s and 440 MB, though Pyright's number includes Node start-up from the pip wrapper. Astral reports ty as the fastest language server on 14 of 17 projects. In my attribute test they also agreed: both widened an attribute's type from every assignment in the class.

Why does ty fail CI with only warnings?

ty check exits with code 1 when there are any diagnostics, warnings included, by default in 1.0.0. A file with one redundant-condition warning and no errors returned 1 in my test. Pass --exit-zero-on-warning to fail only on errors, or set the rule to "error" or "ignore" under [tool.ty.rules] so the decision lives in config.

What is the unsound-return warning in ty?

unsound-return flags a function that returns a value typed as fully or partly Any where a precise type was promised, such as list[Any] for list[str]. It is off by default, so enable it with --warn unsound-return or in [tool.ty.rules]. mypy --strict missed the SQLite example from Astral's post, which returns tuples from a function annotated as returning strings.

  1. ty 1.0: an extremely fast Python type checker and language server, Astral
  2. ty 1.0.0 release, GitHub, astral-sh/ty
  3. Suppression comments, ty documentation
  4. Configuration reference, ty documentation
  5. ty on PyPI, PyPI
  6. Rich (the codebase tested, mypy strict config in pyproject.toml), Textualize

More Posts