Skip to content

Add ty type checking alongside mypy - #15415

Open
reaperhulk wants to merge 1 commit into
mainfrom
claude/mypy-ty-ignore-mismatch-j01iex
Open

Add ty type checking alongside mypy#15415
reaperhulk wants to merge 1 commit into
mainfrom
claude/mypy-ty-ignore-mismatch-j01iex

Conversation

@reaperhulk

Copy link
Copy Markdown
Member

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: 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.

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.

Claude-Session: https://claude.ai/code/session_01FfdhCmHmddyxdZACBwjaeg

Comment thread noxfile.py Outdated
# 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]}"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does not need a constant or a long comment, the comment can be a single sentence

Comment thread noxfile.py Outdated
"noxfile.py",
)

session.run(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in local I think we should replace mypy, and go ty only, since local is optimized for speed

@reaperhulk
reaperhulk force-pushed the claude/mypy-ty-ignore-mismatch-j01iex branch from 200ba54 to e3100f6 Compare August 8, 2026 00:02
Comment thread noxfile.py Outdated
# (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+")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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
reaperhulk force-pushed the claude/mypy-ty-ignore-mismatch-j01iex branch from e3100f6 to 4d2b882 Compare August 8, 2026 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants