Skip to content

style: switch type checker from basedpyright to ty#100

Merged
njzjz merged 9 commits intomasterfrom
copilot/switch-to-ty-type-checker
Feb 17, 2026
Merged

style: switch type checker from basedpyright to ty#100
njzjz merged 9 commits intomasterfrom
copilot/switch-to-ty-type-checker

Conversation

Copy link
Contributor

Copilot AI commented Feb 17, 2026

Migrates type checking from basedpyright to ty (v0.0.17), an extremely fast Rust-based type checker.

Changes

  • Dependencies: Replace basedpyright==1.12.2 with ty==0.0.17 in optional typecheck dependencies
  • CI: Update type-check workflow to run ty instead of basedpyright
  • Configuration: Keep [tool.pyright] section with include = ["dargs"] for compatibility and add [tool.ty.src] configuration with root = ".", include = ["dargs"], and exclude = []

Type error fixes

Type narrowing: Added cast() to help ty narrow union types after isinstance() checks:

# Before
if isinstance(arginfo, (list, tuple)):
    arginfo = Argument("base", dtype=dict, sub_fields=arginfo)  # ty error

# After  
if isinstance(arginfo, (list, tuple)):
    arginfo = Argument("base", dtype=dict, sub_fields=cast(list[Argument], arginfo))

Filter overload resolution: Changed filter(rem.match, ...) to explicit lambdas for correct overload matching:

# Before: rem.match returns Match[str] | None, doesn't match filter overloads
conflict = list(filter(rem.match, reserved))

# After: explicit None check satisfies filter's callable signature
conflict = list(filter(lambda x: rem.match(x) is not None, reserved))

Cleanup: Removed unused type: ignore comments flagged by ty

Note

ty configuration uses [tool.ty.src] as a structured table rather than a simple array like pyright's include field. The src table requires root, include, and exclude fields.

Original prompt

This section details on the original issue you should resolve

<issue_title>Switch from pyright to ty</issue_title>
<issue_description>1. In pyproject.toml, add

[tool.ty]
include = ["dargs"]
  1. In optional dependencies, change basepyright to ty==0.0.17.

  2. In type-check.yml, change the command from basepyright to ty.

  3. Run ty by yourself to see if there are any errors that need you to fix.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits February 17, 2026 14:50
- Update pyproject.toml: change basedpyright to ty==0.0.17
- Update type-check.yml: change command from basedpyright to ty
- Remove [tool.pyright] configuration (ty doesn't use include in config)

Co-authored-by: njzjz <9496702+njzjz@users.noreply.github.com>
- Add type casts in check.py and notebook.py for sub_fields parameter
- Fix filter() calls in dargs.py to use explicit lambdas
- Remove unused type: ignore comments in sphinx.py

Co-authored-by: njzjz <9496702+njzjz@users.noreply.github.com>
Add comments explaining why lambdas are used instead of bound methods
in filter() calls - required for ty type checker compatibility.

Co-authored-by: njzjz <9496702+njzjz@users.noreply.github.com>
Copilot AI changed the title [WIP] Switch from pyright to ty for type checking Switch type checker from basedpyright to ty Feb 17, 2026
Copilot AI requested a review from njzjz February 17, 2026 14:56
@njzjz
Copy link
Member

njzjz commented Feb 17, 2026

pre-commit.ci autofix

@codecov
Copy link

codecov bot commented Feb 17, 2026

Codecov Report

❌ Patch coverage is 30.00000% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.22%. Comparing base (122002c) to head (e24de56).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
dargs/sphinx.py 0.00% 4 Missing ⚠️
dargs/check.py 0.00% 2 Missing ⚠️
dargs/notebook.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #100      +/-   ##
==========================================
- Coverage   74.32%   74.22%   -0.10%     
==========================================
  Files           9        9              
  Lines         810      811       +1     
==========================================
  Hits          602      602              
- Misses        208      209       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
…in permissions

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: Jinzhe Zeng <njzjz@qq.com>
Keep [tool.pyright] section with include field. Not adding [tool.ty]
section yet as ty 0.0.17 doesn't support the include field - it causes
a parse error. Will reply to comment for clarification.

Co-authored-by: njzjz <9496702+njzjz@users.noreply.github.com>
Add ty configuration with src table containing root, include, and exclude
fields as ty requires a struct format, not a simple array.

Co-authored-by: njzjz <9496702+njzjz@users.noreply.github.com>
@njzjz njzjz marked this pull request as ready for review February 17, 2026 20:11
Copilot AI review requested due to automatic review settings February 17, 2026 20:11
@njzjz njzjz changed the title Switch type checker from basedpyright to ty style: switch type checker from basedpyright to ty Feb 17, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates the type checking tool from basedpyright to ty (v0.0.17), a Rust-based type checker. The migration includes updating dependencies, CI configuration, and fixing type errors that ty identified differently than basedpyright.

Changes:

  • Replaced basedpyright==1.12.2 with ty==0.0.17 in optional dependencies
  • Updated CI workflow to run ty check instead of basedpyright
  • Added type casts to help ty narrow union types after isinstance() checks
  • Fixed filter usage with regex match methods for proper type inference
  • Removed unnecessary type: ignore comments

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pyproject.toml Updated typecheck dependency from basedpyright to ty; added [tool.ty.src] configuration
.github/workflows/type-check.yml Changed CI runner and command to use ty instead of basedpyright
dargs/check.py Added cast to help ty narrow list/tuple union after isinstance check
dargs/notebook.py Added cast to help ty narrow list type after isinstance check
dargs/dargs.py Changed filter calls to use explicit lambda for proper type narrowing with regex matches
dargs/sphinx.py Removed unnecessary type: ignore comments from ClassVar declarations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@njzjz njzjz merged commit 2ed9020 into master Feb 17, 2026
20 checks passed
@njzjz njzjz deleted the copilot/switch-to-ty-type-checker branch February 17, 2026 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switch from pyright to ty

2 participants

Comments