Add ty type checking alongside mypy - #15415
Open
reaperhulk wants to merge 1 commit into
Open
Conversation
alex
reviewed
Aug 8, 2026
| # than the interpreter it runs on. Pin it to the running interpreter so ty and | ||
| # mypy agree on which `sys.version_info` branches are reachable. No session | ||
| # pins a python, so this is the version the session venv uses. | ||
| TY_PYTHON_VERSION = f"{sys.version_info[0]}.{sys.version_info[1]}" |
Member
There was a problem hiding this comment.
this does not need a constant or a long comment, the comment can be a single sentence
| "noxfile.py", | ||
| ) | ||
|
|
||
| session.run( |
Member
There was a problem hiding this comment.
in local I think we should replace mypy, and go ty only, since local is optimized for speed
reaperhulk
force-pushed
the
claude/mypy-ty-ignore-mismatch-j01iex
branch
from
August 8, 2026 00:02
200ba54 to
e3100f6
Compare
alex
reviewed
Aug 8, 2026
| # (https://github.com/astral-sh/ty/issues/2797). pytest 9 dropped that | ||
| # pattern but requires Python 3.10+, so skip ty on 3.9. | ||
| if sys.version_info < (3, 10): | ||
| session.log("Skipping ty: needs pytest >= 9, which needs Python 3.10+") |
Member
There was a problem hiding this comment.
@reaperhulk I'm pretty sure this means we need to wait for a fix in ty, I don't love landing this with weird skips.
ty and mypy use incompatible suppression comments: ty ignores any
`# type: ignore[...]` that carries error codes in brackets, and mypy
only recognizes `# type: ignore` when it is the first comment on a
line. Lines that both checkers flag now carry a mypy comment followed
by a ty one, which each tool parses as its own. A bare `# type: ignore`
is honored by both, so the sites that already use one are left alone.
Add ty to the pep8test dependency group and run it in the `flake` and
`local` nox sessions. ty resolves its target version from
`project.requires-python` rather than the interpreter it runs on, so
pass `--python-version` to keep it in step with mypy; otherwise the two
disagree about which `sys.version_info` branch is reachable, and ty
demands `tomli` even on interpreters where the fallback import is dead.
Skip ty on Python 3.9. ty binds away the first parameter of a
`__call__` typed through a Callable-bounded TypeVar, which is how
pytest 8's `_WithException` protocol declares it, so every
`pytest.skip("...")` in the suite is rejected. pytest 9 dropped that
pattern but requires Python 3.10+.
Disable ty's `unused-type-ignore-comment`. One arm of a
`sys.version_info` pair is unreachable at any given version, and ty
reports the blanket ignore mypy needs there as unused. mypy's
`warn_unused_ignores` already covers those comments.
`unused-ignore-comment` (for `# ty: ignore`) stays on, since mypy
cannot check those.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FfdhCmHmddyxdZACBwjaeg
reaperhulk
force-pushed
the
claude/mypy-ty-ignore-mismatch-j01iex
branch
from
August 8, 2026 01:11
e3100f6 to
4d2b882
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds ty side-by-side mypy for typechecking.
ty and mypy use incompatible suppression comments: ty ignores any
# type: ignore[...]that carries error codes in brackets, and mypy only recognizes# type: ignorewhen it is the first comment on a line. Lines that both checkers flag now carry a mypy comment followed by a ty one, which each tool parses as its own. A bare# type: ignoreis honored by both, so the sites that already use one are left alone.Add ty to the pep8test dependency group and run it in the
flakeandlocalnox sessions. ty resolves its target version fromproject.requires-pythonrather than the interpreter it runs on, so pass--python-versionto keep it in step with mypy; otherwise the two disagree about whichsys.version_infobranch is reachable, and ty demandstomlieven on interpreters where the fallback import is dead.Disable ty's
unused-type-ignore-comment. One arm of asys.version_infopair is unreachable at any given version, and ty reports the blanket ignore mypy needs there as unused. mypy'swarn_unused_ignoresalready covers those comments.unused-ignore-comment(for# ty: ignore) stays on, since mypy cannot check those.Claude-Session: https://claude.ai/code/session_01FfdhCmHmddyxdZACBwjaeg