Skip to content

Conversation

vinitkumar
Copy link
Owner

@vinitkumar vinitkumar commented Oct 8, 2025

This PR migrates the project from mypy to ty, Astral's new type checker.

Changes

  • ✅ Replace mypy with ty (run via uvx ty check)
  • ✅ Update pyproject.toml with [tool.ty] configuration
  • ✅ Update GitHub Actions workflow to use uvx ty check
  • ✅ Update AGENT.md, Makefile, and dev.py with new typecheck command
  • ✅ Remove mypy and types-setuptools from requirements-dev.in
  • ✅ Fix type errors detected by ty

Why ty?

  • Modern, fast type checker from Astral (creators of uv and ruff)
  • Better error messages and faster performance
  • Aligns with project's use of uv and ruff

Testing

  • ✅ All 153 tests pass
  • ✅ Ty type checking passes with no errors
  • ✅ No breaking changes to existing code

Documentation

https://docs.astral.sh/ty/

Summary by Sourcery

Migrate static type checking from mypy to Astral's ty and update all related configurations, scripts, CI workflows, documentation, and tests accordingly.

Enhancements:

  • Replace mypy with ty as the type checker and add tool.ty configuration in project metadata

Build:

  • Remove mypy and types-setuptools from development dependencies

CI:

  • Update GitHub Actions workflow to run uvx ty check instead of mypy for json2xml and tests

Documentation:

  • Update AGENT.md to reference uvx ty check as the new typecheck command

Tests:

  • Add type: ignore annotations in test modules to address ty-reported type errors

Chores:

  • Update Makefile and dev.py to invoke uvx ty check instead of mypy

- Replace mypy with ty (Astral's new type checker)
- Update all configuration files (pyproject.toml, setup.cfg)
- Update GitHub Actions workflow to use uvx ty check
- Update AGENT.md, Makefile, and dev.py with new command
- Remove mypy and types-setuptools from requirements-dev.in
- Fix type errors detected by ty (remove unused imports, add type ignore comments for intentional monkey patching)
- All 153 tests pass
- Ty type checking passes with no errors

Amp-Thread-ID: https://ampcode.com/threads/T-3de57a05-de3a-47f2-a4f0-bc95e78d8d13
Co-authored-by: Amp <amp@ampcode.com>
Copy link
Contributor

sourcery-ai bot commented Oct 8, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR migrates the project from mypy to Astral's ty type checker by replacing dependencies and commands, updating configuration and CI workflows, and addressing ty-reported type errors with suppression comments.

Flow diagram for developer type checking commands after migration

flowchart TD
    Developer["Developer"] -->|"make typecheck"| Ty_Check["uvx ty check json2xml tests"]
    Developer -->|"python dev.py typecheck"| Ty_Check
    Developer -->|"uvx ty check json2xml tests"| Ty_Check
Loading

File-Level Changes

Change Details Files
Migrate type checking tool from mypy to ty
  • Removed mypy and types-setuptools from development requirements
  • Replaced mypy commands with uvx ty check in CI workflow, Makefile, dev.py, and documentation
requirements-dev.in
requirements-dev.txt
Makefile
dev.py
AGENT.md
.github/workflows/pythonpackage.yml
Reconfigure project type checking settings
  • Removed the [mypy] section from setup.cfg
  • Added a [tool.ty] configuration stub in pyproject.toml
setup.cfg
pyproject.toml
Resolve ty-reported type errors in tests
  • Added '# type: ignore[assignment]' comments to suppress assignment errors in test modules
tests/test_dict2xml.py
tests/test_utils.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

codecov bot commented Oct 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.30%. Comparing base (b616dd1) to head (6469fd8).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #252   +/-   ##
=======================================
  Coverage   99.30%   99.30%           
=======================================
  Files           3        3           
  Lines         288      288           
=======================================
  Hits          286      286           
  Misses          2        2           
Flag Coverage Δ
unittests 99.30% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • Remove the empty [tool.ty] section from setup.cfg now that all ty configuration lives in pyproject.toml to avoid confusion.
  • Populate the [tool.ty] section in pyproject.toml with the equivalent strictness flags from mypy (e.g., disallow_untyped_defs, no_implicit_optional) to preserve previous type safety guarantees.
  • Instead of sprinkling type: ignore on test assignments, consider updating the function or module type signatures so mocks satisfy the types and avoid masking potential issues.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Remove the empty [tool.ty] section from setup.cfg now that all ty configuration lives in pyproject.toml to avoid confusion.
- Populate the [tool.ty] section in pyproject.toml with the equivalent strictness flags from mypy (e.g., disallow_untyped_defs, no_implicit_optional) to preserve previous type safety guarantees.
- Instead of sprinkling type: ignore on test assignments, consider updating the function or module type signatures so mocks satisfy the types and avoid masking potential issues.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Ty needs to find installed packages in a virtual environment.
Create a venv and activate it before running ty check.
Update the lint workflow to use ty instead of mypy for type checking.
Verified locally:
- ✅ ruff check passed
- ✅ ty check passed
- ✅ all 153 tests passed
sourcery-ai[bot]
sourcery-ai bot previously requested changes Oct 8, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

New security issues found

@vinitkumar vinitkumar merged commit 0314d20 into master Oct 8, 2025
36 of 37 checks passed
@vinitkumar vinitkumar deleted the migrate-mypy-to-ty branch October 8, 2025 11:35
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.

1 participant