Running ty 1.0 on DSPy: 0.27 seconds and one renamed rule
Astral released ty 1.0 on December 1. ty is a Python type checker and language server written in Rust, and the post was on the Hacker News front page this morning. The numbers in it come from Astral, so I’ll label them that way. They say ty is now the default checker at OpenAI, with a median 24x speedup and 73% lower peak memory after migrating. They also say 11.6% of the repositories with a type checker in the 25,000 most-downloaded PyPI packages use ty, which puts it third behind mypy and Pyright.
I can’t check the OpenAI figures. I can check how it behaves on code I have. DSPy is one of my favourite libraries and its repo already runs ty check in CI, so that was the first thing I pointed it at. Everything below ran on 2026-12-02 on an 8-core box with ty 1.0.0, mypy 2.4.1 and pyright 1.1.414 from PyPI, against stanfordnlp/dspy at commit 8faf1c2.
The examples from the announcement
Astral’s post shows four small files where checkers disagree. I retyped them and ran all three tools. mypy ran with --strict, and pyright and ty ran with defaults.
| File | What is wrong at runtime | ty 1.0.0 | mypy 2.4.1 –strict | pyright 1.1.414 |
|---|---|---|---|---|
podium.py |
runner["second"] should be "seconds" in a TypedDict |
1 error, names the key, suggests "seconds" |
3 errors about Mapping[str, object], none names the key |
2 errors, one names the key, one is about list invariance on the return |
batches.py |
valid_batch(iter([1, 2, 3])) has no __len__ |
1 error on that call, Expected Sized & Iterable[int] |
2 errors, both calls rejected because the argument type is inferred as Never |
2 errors, one on the satisfies_all call and one on the iterator |
options.py |
dry_run="true" fails validation, simulate=True is silently dropped |
1 error and 1 pydantic-discarded-extra-argument warning |
5 errors without a plugin, 1 error with pydantic.mypy |
4 errors, two of them about "./exports" not being a Path |
users.py |
fetchall() returns tuples, not str |
passes by default | passes | passes |
I ran options.py at runtime to be sure about the Pydantic part. With dry_run=True you get simulate=True. With simulate=True the argument is thrown away and simulate stays False.
Options(output=PosixPath('exports'), simulate=True)
Options(output=PosixPath('exports'), simulate=False)
The mypy plugin run is the one I’d look at twice. It removes the false str to Path complaints, and it also accepts simulate=True without a word. ty reports the dropped argument as a warning.
The last row needs a flag. users.py returns cursor.fetchall() from a function declared -> list[str]. SQLite gives back one-element tuples, so ", ".join(usernames(db)) raises TypeError when you run it. fetchall() is typed list[Any], and list[Any] is assignable to list[str], so every checker lets it through. ty 1.0 has a new rule for this:
$ ty check --warn unsound-return users.py
warning[unsound-return]: Unsound return statement
--> users.py:6:12
|
4 | def usernames(db: sqlite3.Connection) -> list[str]:
| --------- Expected a subtype of `list[str]` because of the return type
5 | cursor = db.execute("SELECT username FROM users")
6 | return cursor.fetchall()
| ^^^^^^^^^^^^^^^^^ Inferred as `list[Any]`
info: `list[Any]` is assignable to `list[str]`, but not a subtype of `list[str]`
help: Consider using an `assert` to narrow the type prior to the `return` statement
Speed on a real package
I ran each tool three times on the dspy/ directory with no cache and took the median. ty was given an empty config file so it checks the whole package. The DSPy config only includes a handful of files, which comes up below.
Median of three cold runs on
dspy/ at 8faf1c2, 8 cores. mypy ran with --cache-dir=/dev/null. Source: my runs on 2026-12-02.
The tools also report different counts: ty 975 diagnostics, mypy 1,035 errors, pyright 1,400 errors and 8 warnings. Those aren’t comparable, because each tool has different defaults and mypy and pyright are told nothing about DSPy’s config. I’m only using the timing, and it’s one repo on one machine. Astral’s own benchmark says ty was fastest on 16 of 18 projects, which fits what I saw.
What DSPy’s config does with 1.0.0
DSPy’s pyproject.toml has a [tool.ty.src] section that includes six modules under dspy/utils/ and tests/typing. A comment above it says the list grows as internal modules are migrated. The dev dependencies require ty==0.0.89, and .github/workflows/run_tests.yml runs uv run --locked --extra dev ty check. The rules section reads:
[tool.ty.rules]
missing-type-argument = "error"
unsound-return-statement = "error"
unused-ignore-comment = "error"
With 1.0.0 installed and no other change:
$ ty check
warning[renamed-rule]: Rule `unsound-return-statement` has been renamed to `unsound-return`
--> pyproject.toml:150:1
|
150 | unsound-return-statement = "error"
| ^^^^^^^^^^^^^^^^^^^^^^^^
Found 1 diagnostic
$ echo $?
1
ty exits 1 on a warning unless you pass --exit-zero-on-warning, so a version bump alone would turn that CI step red. I changed the line to unsound-return and ran both versions again.
Exit codes of
ty check in the DSPy repo, by version and rule name. Source: my runs on 2026-12-02, DSPy 8faf1c2.
Neither spelling works on both versions. 0.0.89 gives warning[unknown-rule] for the new name, and also exits 1. So the rename and the version bump have to land in the same commit. With both changed, ty check passes on all six modules and on tests/typing, including the # ty: ignore[...] comments that file uses to assert expected errors. unused-ignore-comment is on, so any ignore that stopped matching would have failed the run.
I reverted my edit, and nothing in the clone is changed.
Turning it on for a whole package
The release notes list --add-ignore and --fix as adoption tools. I tried --add-ignore on a copy of dspy/ with the empty config:
$ ty check --config-file ../empty-ty.toml dspy
Found 975 diagnostics
$ ty check --config-file ../empty-ty.toml --add-ignore dspy
Added 975 ignore comments
$ ty check --config-file ../empty-ty.toml dspy
All checks passed!
It changed 797 lines. I’d rather review a short migration list like DSPy’s than a diff that size. A sample of what it adds:
fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB) # ty: ignore[missing-union-attribute]
msvcrt.locking(fd, msvcrt.LK_NBLCK, 1) # ty: ignore[missing-attribute]
The two above come from a file that handles both Linux and Windows, and I assume ty is reporting on the branch for the wrong platform. I haven’t sorted the other ignores into real bugs and noise, so I won’t give a number for either. The command does get you to a green run in a few seconds, but a green run made of 975 ignores doesn’t tell you much about the code.
What I’d do with it
For a new project I’d start with ty and the unsound-return rule as an error, since list[Any] returned as list[str] passes mypy --strict and pyright as shown above. For an existing mypy setup I’d run ty check next to it for a week and read the disagreements, as the table above does for four files. For DSPy I’d send the one-line rename with the version bump as a single PR, and I haven’t opened one.
I haven’t tested the language server or return type inference for unannotated functions. Both are in the 1.0 notes and I only know them from reading.
Resources
- ty 1.0 announcement and the 1.0.0 release notes
- ty rules reference: unsound-return
- stanfordnlp/dspy
pyproject.tomland.github/workflows/run_tests.yml - Hacker News discussion