Skip to content

Mypy ty migration#682

Open
abelaba wants to merge 5 commits intooptimagic-dev:mainfrom
abelaba:mypy-ty-migration
Open

Mypy ty migration#682
abelaba wants to merge 5 commits intooptimagic-dev:mainfrom
abelaba:mypy-ty-migration

Conversation

@abelaba
Copy link
Copy Markdown
Collaborator

@abelaba abelaba commented Apr 24, 2026

Summary

This PR migrates the type-checking from mypy to ty. Type checking is applied to the src, .tools and tests folders.

Changes

Default configuration

  • Added ruff rules ANN001 that checks that function arguments have type annotations and ANN201 that checks that public functions and methods have return type annotations. Previously handled by disallow_incomplete_defs and disallow_untyped_defs in mypy.
  • Mypy behaviors for check_untyped_defs, no_implicit_optional corresponding ty rule, warn_redundant_casts corresponding ty rule and warn_unused_ignores corresponding ty rule are default behaviors in ty.

Mypy Overrides

  • For files that were skipped from checking method type annotations, since this is now handled by ruff I added skips for this files under the ruff section.

Test overrides

  • Ty doesn't have a corresponding flag for ignoring errors like mypy. So I added # ty: ignore[code] for the current errors in the tests folder.

Ignoring missing imports

Additional changes

Next Steps

  • Gradually removing the ty: ignore statements currently added.
  • Updating the enhancement proposal for Type checking

Note

The only rule that can't currently be handled is disallow_any_generics by mypy. This rule doesnt have a corresponding rule in ruff or ty. Current open issue in ruff: astral-sh/ruff#5871

Closes: #677

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

Codecov Report

❌ Patch coverage is 94.18605% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/optimagic/visualization/history_plots.py 0.00% 2 Missing ⚠️
src/estimagic/__init__.py 0.00% 1 Missing ⚠️
src/estimagic/estimation_table.py 66.66% 1 Missing ⚠️
...optimagic/optimizers/_pounders/pounders_history.py 75.00% 1 Missing ⚠️
Files with missing lines Coverage Δ
src/estimagic/estimate_ml.py 82.47% <100.00%> (ø)
src/estimagic/estimate_msm.py 89.68% <100.00%> (ø)
src/optimagic/algorithms.py 88.82% <100.00%> (ø)
src/optimagic/benchmarking/benchmark_reports.py 98.38% <100.00%> (ø)
...c/optimagic/benchmarking/get_benchmark_problems.py 93.87% <100.00%> (ø)
...ptimagic/benchmarking/process_benchmark_results.py 89.33% <100.00%> (ø)
src/optimagic/config.py 100.00% <ø> (ø)
src/optimagic/differentiation/derivatives.py 96.18% <100.00%> (ø)
src/optimagic/differentiation/numdiff_options.py 98.48% <100.00%> (ø)
src/optimagic/logging/logger.py 93.92% <100.00%> (+0.02%) ⬆️
... and 25 more

... and 2 files with indirect coverage changes

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

@abelaba abelaba marked this pull request as ready for review April 24, 2026 09:06
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.

Update type checking to use ty

1 participant