Skip to content

Migrate from mypy to ty#207

Merged
matin merged 3 commits intomainfrom
migrate-mypy-to-ty
Mar 18, 2026
Merged

Migrate from mypy to ty#207
matin merged 3 commits intomainfrom
migrate-mypy-to-ty

Conversation

@matin
Copy link
Copy Markdown
Owner

@matin matin commented Mar 18, 2026

Summary

Replace mypy with ty (from Astral, the ruff/uv team) for type checking.

Changes

  • Replace mypy with ty in Makefile, pyproject.toml, and linting dependency group
  • Fix list[Self] shadowing in data modules (builtins.list[Self])
  • Fix invalid-assignment in Client.user_profile
  • Fix dynamic function attribute in test
  • Set invalid-method-override to warn (intentional Liskov violations in data sorting wrappers)
  • Remove types-requests stub dependency

Test plan

  • uv run ty check — 0 errors, 10 warnings (all intentional)
  • 163 tests pass
  • CodeRabbit review clean

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Replaced type-checking tool from mypy to ty and updated lint configuration.
    • Updated project typing configuration and formatting/lint settings.
    • Standardized type annotations across data modules for consistency and minor internal API typing updates.
  • Bug Fixes
    • Added a guard to telemetry processing to avoid errors when request data is missing.
    • Minor stabilization of HTTP/client property handling.
  • Tests
    • Adjusted pagination test logic to better simulate first-call vs subsequent calls.

- Replace mypy with ty in Makefile, pyproject.toml, and dependencies
- Fix list[Self] shadowing: use builtins.list[Self] in data modules
  where the list() classmethod shadows the builtin
- Fix invalid-assignment in Client.user_profile (narrow type before
  assigning)
- Fix dynamic function attribute in test_training_status (use dict)
- Set invalid-method-override to warn (intentional Liskov violations
  in data subclass sorting wrappers)
- Remove types-requests dependency (ty doesn't need stubs)

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cdb26410-4824-4e5d-ace3-5057035b5bd1

📥 Commits

Reviewing files that changed from the base of the PR and between a44760d and feb6612.

📒 Files selected for processing (1)
  • src/garth/telemetry.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/garth/telemetry.py

Walkthrough

Swap mypy for ty in linting/config, adjust Ruff options, standardize multiple data return annotations to builtins.list[Self], remove @classmethod from SleepData.list, tweak an HTTP property assignment, update a test call counter, and guard telemetry hook against missing request.

Changes

Cohort / File(s) Summary
Build / Tooling
Makefile, pyproject.toml
Replace mypy+types with ty (new [tool.ty] config), update lint dependency group, and add Ruff options like indent-width and target-version.
Core data typing updates
src/garth/data/_base.py, src/garth/data/activity.py, src/garth/data/body_battery/events.py, src/garth/data/daily_sleep_data.py, src/garth/data/fitness_stats.py, src/garth/data/garmin_scores.py, src/garth/data/hrv.py, src/garth/data/morning_training_readiness.py, src/garth/data/training_readiness.py, src/garth/data/weight.py
Import builtins and change list[Self] return annotations to builtins.list[Self] (and related list -> builtins.list) across .get/.list signatures.
Sleep & tests
src/garth/data/sleep.py, tests/stats/test_training_status.py
Remove @classmethod from SleepData.list and change its return annotation; test replaces attribute-based call counter with a dict-based counter and alters side_effect to return data only on first call.
HTTP & telemetry
src/garth/http.py, src/garth/telemetry.py
http.py: use intermediate variable for connectapi result before validation/assignment. telemetry.py: early return in _response_hook when response.request is None.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.73% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Migrate from mypy to ty' clearly and concisely describes the main objective of the pull request: replacing the mypy type checker with ty (Astral).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch migrate-mypy-to-ty
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.97%. Comparing base (f2c61ff) to head (feb6612).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #207   +/-   ##
=======================================
  Coverage   99.97%   99.97%           
=======================================
  Files          68       68           
  Lines        3547     3556    +9     
=======================================
+ Hits         3546     3555    +9     
  Misses          1        1           
Flag Coverage Δ
unittests 99.97% <100.00%> (+<0.01%) ⬆️

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.

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

- Add None guard for Response.request in telemetry hook (ty catches
  that PreparedRequest can be None, mypy didn't)
- Only type-check src/ with ty (CI lint job doesn't have test deps)

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pyproject.toml`:
- Around line 55-57: The ty config currently includes tests (tool.ty.src include
= ["src", "tests"]) but pytest is only in the testing dependency group, so
type-checking during the linting CI (which installs only --group linting) will
fail to resolve pytest imports; fix by either removing "tests" from tool.ty.src
so ty only checks src, or add pytest to the linting dependency group (move or
duplicate the pytest entry from the testing group into the linting group) so
imports resolve during lint CI. Ensure you update the pyproject.toml entry for
tool.ty.src or the dependency groups accordingly and keep the change consistent
with CI install flags.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 18a9abe2-b31e-4b14-af8a-c88e6b7c7ab1

📥 Commits

Reviewing files that changed from the base of the PR and between f2c61ff and a1b4262.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (15)
  • Makefile
  • pyproject.toml
  • src/garth/data/_base.py
  • src/garth/data/activity.py
  • src/garth/data/body_battery/events.py
  • src/garth/data/daily_sleep_data.py
  • src/garth/data/fitness_stats.py
  • src/garth/data/garmin_scores.py
  • src/garth/data/hrv.py
  • src/garth/data/morning_training_readiness.py
  • src/garth/data/sleep.py
  • src/garth/data/training_readiness.py
  • src/garth/data/weight.py
  • src/garth/http.py
  • tests/stats/test_training_status.py

Never None for completed responses in practice.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@matin matin merged commit 88d7402 into main Mar 18, 2026
24 of 26 checks passed
@matin matin deleted the migrate-mypy-to-ty branch March 18, 2026 09:23
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