Add ty as type checker alongside pyright#20474
Open
LeonarddeR wants to merge 4 commits into
Open
Conversation
- Drop [tool.ty.src] entries that duplicate ty's built-in defaults (.git, .tox, .venv, __pycache__) or are dead for ty (include, sconstruct/sconscript: ty only checks .py/.pyw files) - Skip ty hook on pre-commit.ci (needs project .venv, like pyright) and on commits without Python changes (upstream hook sets always_run) - Note that hook rev matches the ty version pinned in pyproject - Gate allTestsPass on typeCheckTy; add permissions block to the job - Rename typeCheck job and script to typeCheckPyright for symmetry with typeCheckTy Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The ty pre-commit hook needs the built comInterfaces COM stubs (same as pyright), which the autofix job's plain checkout does not generate. Without this it fails with spurious unresolved-reference errors on wildcard-imported UIA constants. The dedicated typeCheckTy job in testAndPublish.yml still runs it against the built cache. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Contributor
|
ty v0.0.58 has been released. ty is updated frequently—what is our update strategy? Do we update promptly? |
Collaborator
Author
Fair point. I think this has to be added with the regular update cadence, so when ruff/uv are updated. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces ty as an additional Python type checker alongside the existing pyright tooling, wiring it into NVDA’s dependency set, local lint script, pre-commit, CI, and developer documentation so ty can gate changes during an evaluation period.
Changes:
- Add
ty==0.0.57to the lint dependency group and lockfile, and configure ty inpyproject.toml. - Add a dedicated CI job + script for
ty check, and rename the existing pyright CI script/job for symmetry. - Run ty as part of
runlint.batand add a pre-commit hook for ty; update automated testing docs accordingly.
Reviewed changes
Copilot reviewed 7 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
uv.lock |
Adds ty to the locked lint dependencies for Windows. |
pyproject.toml |
Introduces [tool.ty] configuration and pins ty==0.0.57 in the lint group. |
runlint.bat |
Runs ty check in addition to existing ruff + pyright steps. |
ci/scripts/tests/typeCheckTy.ps1 |
New CI helper script to run ty and publish failures to the job summary. |
ci/scripts/tests/typeCheckPyright.ps1 |
New/renamed CI helper script to run pyright and publish failures to the job summary. |
.github/workflows/testAndPublish.yml |
Adds typeCheckTy job and renames the existing pyright type-check job; both gate allTestsPass. |
.pre-commit-config.yaml |
Adds an upstream ty pre-commit hook and skips it on pre-commit.ci. |
.github/workflows/autofix.yml |
Skips the new ty hook in autofix workflow’s lint gate. |
projectDocs/testing/automated.md |
Documents that both pyright and ty are used and that runlint.bat runs both. |
Comment on lines
+30
to
+34
| if "%1" NEQ "" ( | ||
| call uv run --group lint --directory "%here%" ty check > %1/ty-output.txt | ||
| ) else ( | ||
| call uv run --group lint --directory "%here%" ty check | ||
| ) |
Comment on lines
+148
to
+154
| - id: ty | ||
| name: type check with ty | ||
| # The upstream hook sets always_run, making every commit | ||
| # (even ones without python changes) pay for a full ty check. | ||
| always_run: false | ||
| types: [python] | ||
|
|
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.
Link to issue number:
Part of #19393
Summary of the issue:
NVDA type-checks with pyright, which is slow and bundles a Node.js runtime. Many pyright rules are disabled to suppress pre-existing violations, leaving those categories unprotected against new violations. In #19393 I proposed swapping pyright for ty (Astral, Rust-based: fast, no Node, gradual typing).
Description of user facing changes:
None.
Description of developer facing changes:
pyproject.toml([tool.ty]). The config only contains what deviates from ty's defaults (e.g. directories covered by ty's built-in excludes are not repeated).typeCheckTy,ci/scripts/tests/typeCheckTy.ps1) runs in parallel with the existing pyright job. The existing job and script are renamed totypeCheckPyrightfor symmetry. Both jobs gateallTestsPass, so ty failures block PRs.runlint.batnow runs both pyright and ty.astral-sh/ty-pre-commit,rev: v0.0.57, kept in sync with the pyproject pin). The upstream hook'salways_runis overridden so commits without Python changes don't pay for a fullty check, and the hook is skipped on pre-commit.ci for the same reason as pyright (it needs the project.venv).Description of development approach:
ty's rule taxonomy differs entirely from pyright's, so the config was tuned empirically: rules that flood violations on the current codebase are set to
"ignore"(each annotated with its count, analogous to the existing[tool.pyright]leniency), reaching a cleanty checkwith zero code changes. pyright removal is a planned follow-up once ty proves stable in CI.Testing strategy:
uv run ty checkexits 0 ("All checks passed!") on the codebase.uv run pyrightstill exits 0 (its config is untouched).unresolved-reference), including in.pywfiles discovered project-wide without an explicitinclude.uv run prek run ty --all-files); CI ty job added.Known issues with pull request:
"ignore"(annotated with counts, ~82 warnings total), matching the current pyright leniency rather than fixing the underlying issues.unresolved-attribute,not-subscriptable) likely hide some None-safety issues; a follow-up can progressively re-enable rules.vscode-nvdasubmodule and is a separate PR.Code Review Checklist: