Python tooling has consolidated fast around Astral's stack: uv for packages, ruff for linting and formatting, and ty for Rust-speed static type checking.
While migrate-to-uv handles moving away from Poetry/Pipenv, moving an existing codebase from mypy, pyright, or basedpyright to ty still had a tedious manual step:
- Translating
mypy.ini,setup.cfg,pyrightconfig.json, or[tool.mypy]/[tool.pyright]into[tool.ty.*]. - Converting per-module overrides (
[mypy-tests.*],executionEnvironments) into[[tool.ty.overrides]]orallowed-unresolved-imports. - Rewriting dozens or hundreds of
# type: ignore[arg-type]and# pyright: ignore[reportAttributeAccessIssue]comments to# ty: ignore[...]without breaking strings or docstrings.
So I built ty-migrate — a zero-dependency Python 3.11+ CLI published on PyPI.
Try It Without Installing
Preview what would change on your project without modifying any files:
uvx ty-migrate --rewrite-ignores --dry-run --diff --report Apply the migration and immediately verify with ty check:
uvx ty-migrate --rewrite-ignores --report --verify What It Automates
1. Multi-Format Config Discovery & Parsing
ty-migrate discovers and normalizes:
- Mypy:
mypy.ini,.mypy.ini,setup.cfg([mypy]+[mypy-*]), andpyproject.toml([tool.mypy]+[[tool.mypy.overrides]]). - Pyright / Basedpyright:
pyrightconfig.json(JSONC-safe — strips//,/* */, and trailing commas without breaking URLs in strings) andpyproject.toml([tool.pyright],[tool.basedpyright], andexecutionEnvironments).
2. Idiomatic [tool.ty.*] Generation
Instead of naive key renaming, it maps settings into ty's actual structure:
-
python_version/pythonVersion→[tool.ty.environment].python-version -
mypy_path/extraPaths→[tool.ty.environment].extra-paths - Pure
ignore_missing_imports = Truemodule sections (like[mypy-vendor_missing.*]) →[tool.ty.analysis].allowed-unresolved-imports -
disable_error_code/report*→[tool.ty.rules]validated againstty's official 163-rule catalog (ignore/warn/error). - Safely updates existing
pyproject.tomlfiles without touching[project]or[tool.ruff], or writes a standalonety.toml.
3. Tokenizer-Safe Inline Ignore Rewriting
Regex find-and-replace over Python source files inevitably corrupts docstrings, test fixtures, or string literals mentioning # type: ignore.
ty-migrate uses Python's standard-library tokenize module so only real COMMENT tokens are rewritten:
"""Docstring mentioning # type: ignore[arg-type] stays untouched.""" # Before: x: int = "bad" # type: ignore[assignment] # legacy fixture y = obj.x # pyright: ignore[reportAttributeAccessIssue] # After: x: int = "bad" # ty: ignore[invalid-assignment] # legacy fixture y = obj.x # ty: ignore[missing-attribute, invalid-attribute-access] By default, bare # type: ignore and unmapped plugin error codes are left untouched (--unmapped-strategy keep) rather than silently widening ignores.
4. Honest Audit Reporting (--report & --check)
ty has real behavioral differences from mypy and pyright — for instance, ty checks unannotated function bodies unconditionally (check_untyped_defs is always on), has no single strict = True flag, and does not run mypy plugins.
Rather than silently ignoring those keys, --report breaks every option down into Translated, Guidance / Implicit in ty, and Unmapped, and --check returns exit code 3 in CI if anything needs manual review.
Links
If you try it on a real codebase and hit an unmapped error code or edge case, open an issue or PR!
