• Python
  • type checking
  • ty
  • mypy

ty 1.0 vs mypy: what each Python type checker catches, and how to adopt one without fixing everything first

A beginner's comparison of Astral's ty 1.x and mypy on the same small project, run with ty 1.1.0 and mypy 2.4.1: which errors each reports in annotated and unannotated code, why, and how ty's baseline lets an existing project turn on type checking in CI today.

You inherit a Python project with a few thousand lines, some type hints, and no type checker in CI. A teammate says “add mypy”. Another says Astral just released ty 1.0 and it is much faster. You try one, it prints 400 errors, and the idea dies in a pull request nobody wants to review.

This article helps you make that choice and avoid that ending. I ran both tools on the same small project, with deliberate bugs, and compared what each reported. Then I used ty’s baseline feature to switch type checking on in an existing project without fixing old errors first.

Versions used: ty 1.1.0 and mypy 2.4.1, both installed with pip into a virtual environment on Linux with Python 3.11.18. Results can change between releases, especially for ty, whose release notes say: “Minor releases may include changes to type-checking behavior that introduce new type errors.” ty 1.0.0 release notes

The words you need

  • Type hint (annotation): text such as price: float or -> str that says which type a value should have. Python itself does not enforce it at run time.
  • Type checker: a program that reads your code without running it and reports places where the types cannot fit, such as passing a string where a number is expected.
  • Unannotated code: functions and variables without type hints. Most real projects have a lot of it.
  • Gradual typing: the approach Python uses: annotated and unannotated code live side by side, and the checker must decide how strict to be with the unannotated part.
  • Any / Unknown: a type that means “could be anything”, so the checker allows every operation on it. mypy writes it Any; ty shows Unknown when it falls back to it implicitly. ty typing FAQ
  • Baseline: a file that records the errors a project already has, so a check fails only on new ones.
  • CI (continuous integration): the automated checks that run on every pull request.

The two tools in one paragraph each

mypy is the original Python type checker, written in Python and maintained by the Python typing community for more than a decade. Most tutorials, Stack Overflow answers and existing configurations assume it.

ty is a type checker and language server (the part that powers editor features such as go-to-definition) written in Rust by Astral, the company behind Ruff and uv. Version 1.0 was released on December 1, 2026, and Astral now recommends it for production use. ty 1.0 announcement The 1.0.0 release notes report that ty passes 95% of the test files in Python’s typing conformance suite (a shared set of tests for how checkers follow the typing specification), compared with 57% for mypy, and the announcement says it was the fastest checker on 16 of 18 benchmark projects. Those numbers come from Astral, and the announcement itself calls the conformance suite an imperfect proxy, so treat them as a reason to try ty, not as proof that it fits your project.

The test project

Create a folder with this pyproject.toml:

[project]
name = "shop"
version = "0.1.0"
requires-python = ">=3.11"

and a file shop/prices.py (plus an empty shop/__init__.py):

def find_price(prices, name):
    # unannotated: no type hints at all
    for item, price in prices.items():
        if item == name:
            return price
    return None


def total(prices: dict[str, float], names: list[str]) -> float:
    result = 0
    for name in names:
        result += prices[name]
    return result


def label(prices):
    price = find_price(prices, "tea")
    return "Tea costs " + price.upper()


def discount(amount: float, percent: int) -> float:
    return amount - amount * percent / 100


print(discount("12.5", 10))

It contains three kinds of problems:

  1. discount("12.5", 10) passes a string to an annotated float parameter: a real bug in annotated code.
  2. label() calls .upper() on a value that can be None (when the item is missing): a real bug in unannotated code.
  3. total() starts result as the integer 0 and then adds floats to it: the code works at run time, but the variable’s type changes.

Install both tools in a virtual environment and run them from the project folder:

python3 -m venv .venv
.venv/bin/pip install ty==1.1.0 mypy==2.4.1
.venv/bin/ty check
.venv/bin/mypy shop

What each tool reported

mypy (default settings) found two errors:

shop/prices.py:12: error: Incompatible types in assignment (expression has type "float", variable has type "int")  [assignment]
shop/prices.py:25: error: Argument 1 to "discount" has incompatible type "str"; expected "float"  [arg-type]
Found 2 errors in 1 file (checked 2 source files)

ty (default settings) found one (output shortened; ty also prints where discount is defined):

error[invalid-argument-type]: Argument to function `discount` is incorrect
  --> shop/prices.py:25:16
   |
25 | print(discount("12.5", 10))
   |                ^^^^^^ Expected `float`, found `Literal["12.5"]`
Found 1 diagnostic

Both caught the annotated bug. They differ on the other two, and the reasons are worth understanding.

Difference 1: a variable whose type changes

mypy infers a variable’s type from its first assignment, so result = 0 makes result an int and adding a float later is an error. mypy: type inference ty did not report it: in this test it let the unannotated result hold an int first and a float later. ty’s FAQ states that it “does not report an error for unannotated function parameters, return types, or variables.” ty typing FAQ

Neither answer is wrong. mypy’s is stricter; ty’s avoids errors on code that runs fine. If you want the intent to be explicit for both tools, write result: float = 0.

Difference 2: bugs inside unannotated functions

Neither tool reported the None bug in label() by default, but for different reasons:

  • mypy does not check the body of a function that has no annotations at all unless you pass --check-untyped-defs. mypy command line Even with that flag it stayed silent here, because the unannotated find_price returns Any, and Any allows .upper().
  • ty does check unannotated bodies, but by default it does not infer return types of unannotated functions. The setting analysis.return-type-inference defaults to "never". ty configuration

Turning that setting on changed the result (output shortened; the run also repeats the discount error and ends with Found 2 diagnostics):

.venv/bin/ty check -c 'analysis.return-type-inference="always"'
error[missing-union-attribute]: Attribute `upper` is not defined on `None` in union `Unknown | None`
  --> shop/prices.py:18:27
   |
18 |     return "Tea costs " + price.upper()
   |                           ^^^^^^^^^^^

ty inferred that find_price returns “something unknown, or None”, and flagged the None case. This is the most useful difference for a project with little annotation: with return type inference on, ty found a real bug without a single type hint in the functions involved.

A smaller example shows the “unannotated body” rule on its own. Given this file:

def greet():
    count = 3
    return "Hello " + count

ty check reports unsupported-operator on the last line with default settings. mypy prints Success: no issues found, and only reports Unsupported operand types for + ("str" and "int") with --check-untyped-defs.

Summary table

Case in the test mypy 2.4.1 default mypy --check-untyped-defs ty 1.1.0 default ty with return type inference
Wrong argument to annotated function reported reported reported reported
Unannotated variable changes type reported reported not reported not reported
Error inside an unannotated function not reported reported reported reported
None from an unannotated helper not reported not reported not reported reported

Adopting ty in an existing project with a baseline

Now the 400-errors problem. ty 1.x can record existing diagnostics in a baseline file so CI fails only on new ones. Baselines are marked preview: “The file format may change between ty releases.” ty configuration

  1. Configure the baseline path. Add this to pyproject.toml (the analysis setting is optional; it is what made ty find the None bug above):

    [tool.ty]
    baseline = "ty-baseline.json"
    
    [tool.ty.analysis]
    return-type-inference = "always"
  2. Record today’s errors. Run:

    .venv/bin/ty check --update-baseline

    On the test project it printed Updated baseline ... with 2 diagnostics. and exited with code 0. The file lists each diagnostic by file, rule and column range, for example "rule": "invalid-argument-type".

  3. Commit ty-baseline.json and run ty check in CI. A plain ty check now prints All checks passed! and exits with 0.

  4. Check that new bugs still fail. I added a new function:

    def shipping(weight: float) -> float:
        return weight * "2"

    ty check reported error[unsupported-operator]: Unsupported `*` operation for the new line only and exited with code 1. The two baselined errors stayed quiet.

  5. Check that unrelated edits do not break the baseline. I removed that function and inserted two lines (a docstring) at the top of the file, which shifted every old error down. ty check still passed: the baseline stores column ranges and rule names, not line numbers, so it survived the shift in this test.

  6. Pay the debt down. Fix a few baselined errors at a time and run ty check --update-baseline again so the file shrinks.

If you prefer the old errors to be visible in the code, ty check --add-ignore writes a comment on each line instead. Use it instead of a baseline, not on top of one: with a baseline configured, the baselined errors are already suppressed and get no comments. On the test project it added # ty: ignore[missing-union-attribute] and # ty: ignore[invalid-argument-type] and printed Added 2 ignore comments. The release notes list it without a preview label, unlike baselines, but it puts noise in every file. ty 1.0.0 release notes

mypy has no built-in baseline file. The usual mypy approach is per-module ignore_errors = true overrides in its configuration, or # type: ignore comments, then tightening module by module.

Which one should you choose?

These are recommendations based on the tests above and the cited documentation, not rules:

  • Choose ty for a project with many unannotated functions, when editor speed matters, or when you want to start checking today with a baseline. Turn on return-type-inference to get value from unannotated code. Pin the exact ty version in CI (for example ty==1.1.0) and update it on purpose, because minor releases may add new errors.
  • Stay with mypy when the project already runs mypy cleanly, relies on mypy plugins, or depends on mypy-specific behavior such as its strict variable inference. A switch would mostly produce a diff of differently worded errors.
  • Running both for a while is reasonable in a library that others type-check with different tools. Expect them to disagree on edge cases; decide which one blocks a merge.

If your project targets a recent Python, set [tool.ty.environment] python-version or requires-python so ty uses the right syntax rules. ty 1.1.0 accepts versions up to 3.15, which matters for new syntax such as the explicit lazy imports in Python 3.15.

Common mistakes

  • Comparing tools by error count. ty’s single error versus mypy’s two above does not mean either is better; the errors were different ones.
  • Assuming “unannotated” means “unchecked”. True for mypy by default, false for ty.
  • Not pinning the version. An unpinned ty in CI can fail a pull request that changed nothing, after a new minor release.
  • Treating the baseline as permanent. It is a debt list. If nobody updates it, the old bugs stay forever.
  • Forgetting the environment. Both tools need your installed packages to resolve third-party imports; run them inside the project’s virtual environment or point ty at it with --python.

Conclusion

On the same code, mypy and ty 1.x disagree in predictable ways: mypy is stricter about variables whose type changes, while ty checks unannotated function bodies by default and, with return type inference on, finds None bugs that mypy misses in unannotated code. For a project with little annotation and no type checker yet, ty with a committed baseline is a practical way to block new type errors this week without a 400-error cleanup. For a project already clean under mypy, there is no urgent reason to switch. Whichever you pick, pin its version and let CI enforce it.

Written by Duy Pham Independent developer. I build the apps on this site and write about how they work.

More about me